I am currently fetching my data from my database like this:
select format(sum(numberField),2) as numberField from table
Which returns a number formatted like this : 1,234.56.
Livecode does not seem to like it when I try and add two numbers with this formatting together. I have looked at selecting the data without formatting but am then having trouble formatting inside LiveCode. I was always used to using numberFormat to format my data but this does not seem to work either.
Can anyone suggest the best way for me to get the formatting I require.
Thanks.
Nic
Formatting Numbers for Arithmatic
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Formatting Numbers for Arithmatic
Here's a lunch-at-the-keyboard function - I think it works OK
1234.56 => 1,234.56
...etc...

Code: Select all
function nFormat pVal
local tInt, tDec, tLength, tIndex
set itemDel to "."
put item -1 of pVal into tDec
delete item -1 of pVal
put length(pVal) into tLength
repeat with tIndex = (tLength div 3) * 3 to 3 step -3
if tIndex < tLength then put comma before char -tIndex of pVal
end repeat
return pVal & "." & tDec
end nFormat
1234.56 => 1,234.56
...etc...
LiveCode Development & Training : http://splash21.com
Re: Formatting Numbers for Arithmatic
Hi.
Why not just replace comma with empty in the number?
Are there other characters that will break an arithmetic operation as well, like "$"? If so, you need to lose them too.
Craig Newman
Why not just replace comma with empty in the number?
Are there other characters that will break an arithmetic operation as well, like "$"? If so, you need to lose them too.
Craig Newman
Re: Formatting Numbers for Arithmatic
Thank you!