Formatting Numbers with Decimal Places

J

James

Is it possible to format numbers that are displayed in a text box in such a
way that fractional values are displayed to 2 decimal places and whole
numbers are not displayed with any decimal point?

I have tried using the code:
Format (value here, "0.##")

This works okay and works nicely for the fractional values, but when whole
numbers enter the text box the decimal point is displayed without any
trailing values. For example, "4880." Instead, I would like "4880" to be
displayed.

Thanks in advance for any suggestions,

James
 
T

Tom Ogilvy

s = Format (value here, "0.##")
if right(s,1) = "." then
s = Replace(s,".","")
end if
 
D

Dave Peterson

Another way:

Dim myVal as double
Dim myFormat as string

myVal = 12.12

if int(myval) = myval then
myformat = "0"
else
myformat = "0.00"
end if

msgbox format(myval,myformat)

There's a difference between Tom's suggestion and this one.

What do you want to see with a value like 12.0003?
 
D

Dave Peterson

Me?

I don't care.

But sometimes people want to see different things if the value isn't really a
counting number.

Or am I missing the real point?
 

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