Re: Formating numbers using commas?
Sim,
Here's something I made once:
-- takes an integer and makes a sequence with commas every 3 digits:
function PrettyNumbers(object aNumber)
sequence PrettyNumber, Temp
integer TriCounter
PrettyNumber = {}
Temp = {}
TriCounter = 0
Temp = sprint(aNumber)
for n = length(Temp) to 1 by -1 do
PrettyNumber = prepend(PrettyNumber,Temp[n])
TriCounter += 1
if TriCounter = 3 and n != 1 then
PrettyNumber = prepend(PrettyNumber,',')
end if
if TriCounter = 3 then
TriCounter = 0
end if
end for
return PrettyNumber
end function
--------------------------------
----- Original Message -----
From: "Sim" <starion5wolf at hotmail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 29, 2002 10:25 PM
Subject: Formating numbers using commas?
>
> Hi,
> I'm trying to create a small calculator for Win32, but I can't
> format numbers correctly. Is there a way to format an number / atom
> using printf() or sprintf() ? I can use this code to write the number in
> decimals, but I don't see any commas: sprintf("%d", 1234567). I'd like
> to see: 1,234,567 I tried changing the formating numbers to %0.2d, but
> that didn't work. I tried looking through the Euphoria documentation,
> Win32 Demos and other programs, but I can't find any answers.
>
>
> Any ideas or tips would be appreciated.
>
> Thanks!
>
>
>
>
|
Not Categorized, Please Help
|
|