This topic is locked
[SOLVED]

 No Decimal If Zero

1/28/2013 7:24:26 PM
ASPRunnerPro General questions
J
JohnLug author

I have a table where most entries/results would be whole numbers. But sometimes a decimal like .5 05 ,05

How can I set it so if it's, for example, 55.00 , it only shows 55 , but if it's 55.05 , it will show it that way

Sergey Kornilov admin 1/30/2013

You will have to format it manually in this case.
Set 'View as' format to 'Custom' and use FormatNumber function to achieve what you looking for:

http://www.w3schools.com/vbscript/func_formatnumber.asp

J
JohnLug author 2/6/2013

That link gives good examples, but not what I'm needing. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=69708&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
This is what I need...
Input Shows

55 55

55.5 55.5

55.05 55.05

55.050 55.05

Sergey Kornilov admin 2/6/2013

This is what you need to use, just remove the trailing zero after applying FormatNumber function.

J
JohnLug author 2/6/2013

Sorry, but I'm missing something. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=69716&image=1&table=forumreplies' class='bbc_emoticon' alt=':o' />
In that example page, it doesn't show how to take out extra zeros after the decimal.
I need it set to two decimal places, but if an entry calls for 1 - like 3.3

I need it to show 3.3 not 3.30

Sergey Kornilov admin 2/6/2013

Yes, it doesn't show that. You need to apply the FormatNumber function first, then check if resulting string has "0" at the end of it and remove it if required.
Check VBScript functions Right(), Left() and Len() for inspiration.

More info: http://www.aspisfun.com/functions/string/

J
JohnLug author 2/7/2013

Thanks to Sergey, this now works!!
set 'View as' type of the field in question to Custom and try the following code there:
strValue = CStr(FormatNumber(strValue,2))

if Right(strValue,1)="0" then

strValue = Left(strValue, Len(strValue)-1)

end if