|
-
Nov 21st, 2011, 12:40 PM
#1
Thread Starter
Member
Help me with some fn in vb/vba...
hey i need to know how to get a value with 2 decimals..
i tried with e.g a = 3.102 round ( a,2) i get the value as 3.1 and not as 3.10...i want to get the value as 3.10 ..how can i make it..??
-
Nov 21st, 2011, 03:32 PM
#2
Re: Help me with some fn in vb/vba...
to show leading or trailing zeroes you must display the value as a string, using format command
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 21st, 2011, 04:39 PM
#3
Re: Help me with some fn in vb/vba...
Or you could format the cells with a number format. If you need the value to actually round because you are going to perform operations with it then use the formula you posted and format the cell as number. But if you only need it to display with 2 decimals and do not care if the actual value has more precision then just format the cell and leave the number as is.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Nov 21st, 2011, 08:16 PM
#4
Thread Starter
Member
Re: Help me with some fn in vb/vba...
hey leave off excel...i am using MicroStation (a drafting software for Mech Engineers ). I actually want a VB code.
a= 3.100
b=round(a,2)
msgbox(b)
I should get the value in msgbox as 3.10
now what shall i do....I can't use any excel worksheet functions here ...
-
Nov 21st, 2011, 08:40 PM
#5
Thread Starter
Member
Re: Help me with some fn in vb/vba...
i tried with this Math.Round (3.102, 2) but still i din get desired result
-
Nov 21st, 2011, 08:49 PM
#6
Thread Starter
Member
Re: Help me with some fn in vb/vba...
b = Format(Round(3.102, 2), "#0.00")
Thank You Guys this works fine
-
Nov 22nd, 2011, 09:35 AM
#7
Re: Help me with some fn in vb/vba...
 Originally Posted by dmanojkmr
hey leave off excel...i am using MicroStation (a drafting software for Mech Engineers ). I actually want a VB code.
a= 3.100
b=round(a,2)
msgbox(b)
I should get the value in msgbox as 3.10
now what shall i do....I can't use any excel worksheet functions here ...
Then you posted in the wrong forum
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Nov 23rd, 2011, 05:23 AM
#8
Re: Help me with some fn in vb/vba...
Then you posted in the wrong forum
AFAIK this is the correct forum for all vba and other application automating
b = Format(Round(3.102, 2), "#0.00")
you do not need to round the number, if you only need the 2 digit decimal for display purposes, the format will do that
round returns a value,
format returns a string
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 23rd, 2011, 08:47 AM
#9
Thread Starter
Member
Re: Help me with some fn in vb/vba...
oh fine....but if i need the value of 3.167 as 3.17 will the format function round it's value...??? i suppose it just displays the result as 3.16
-
Nov 23rd, 2011, 10:59 AM
#10
Re: Help me with some fn in vb/vba...
correct, in your case you need Round and Format. Format since you need a display of "3.00"!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|