Page 1 of 1

Inserting comma in numbers

Posted: Fri Aug 21, 2009 2:39 am
by urbaud
How would I insert a comma in the following number: 27155.34? I would like to know how to format the number so it will look like this: 27,155.34. I can't find any reference to it in the Dictionary or in Dan Shafer's book. Can anyone help?

Posted: Fri Aug 21, 2009 8:45 am
by Mark
Urbaud,

You might use this function.

Code: Select all

constant dot = "."
function formatNumber theNumber
     put fld 1 into theNumber
     if theNumber contains dot then
          set the itemDelimiter to dot
          put last item of theNumber into myDecimals
          delete last item of theNumber
     else
          put "00" into myDecimals
     end if
     repeat with x = (number of chars of theNumber- 2) down to 4 step -3
          put comma before char x of theNumber
     end repeat
     return theNumber & dot & myDecimals
end formatNumber
Best regards,

Mark

Posted: Fri Aug 21, 2009 9:56 am
by SparkOut
Hi Urbaud,
Just remember that when you retrieve a number displayed with the comma inserted, then to RunRev it is actually handled as a string.
There is some more info about number formats and how to handle them in the forum, this thread for instance http://forums.runrev.com/phpBB2/viewtop ... 2696#12696 refers to setProp/getProp solutions to handle the display and retrieval options - which is, of course, only one of the ways RunRev lets you skin the cat.