Inserting comma in numbers
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Inserting comma in numbers
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?
urbaud
Urbaud,
You might use this function.
Best regards,
Mark
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
Mark
Last edited by Mark on Fri Aug 21, 2009 10:46 am, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
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.
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.