String to Rounded Integer

S

StumpedAgain

I'm trying to make some cell values integers. The database saves the
fractions as a string and I can't seem to get them to convert to integers so
that I can round them.

What I'd like:
0.135450617647059 (string)
to
0.135 (integer or string... guess I don't really care)

What I've tried:
x = Round(Val(ActiveSheet.Cells(brow, "K")), 3)
y = Round(ActiveSheet.Cells(crow, "J"), 3)

I've tried using Val and CInt and they didn't work for me. Any suggestions?
Thanks!
 
S

StumpedAgain

Now that I think about it, it would be best to convert it to an integer so
that I can round. Thanks!
 
G

Gary Keramidas

this works for me, wit a test srting in A1.

Sub test()
Dim num As Double
num = Round(Val(Range("A1")), 3)
MsgBox num
End Sub
 
R

Ron Rosenfeld

Now that I think about it, it would be best to convert it to an integer so
that I can round. Thanks!

If you convert it to an integer, you will lose everything after the decimal!
And Integer variables are stored as 16-bit (2-byte) numbers ranging in value
from -32,768 to 32,767. This may be limiting.

See Gary's solution.
--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top