Re: How can I format an integer ?
Re: How can I format an integer ?
- Subject: Re: How can I format an integer ?
- From: KOENIG Yvan <email@hidden>
- Date: Thu, 6 Nov 2008 11:21:31 +0100
Le 6 nov. 2008 à 11:05, Peter Waibel a écrit :
on FormatInt(theNum, theSeparator)
if theNum > 999 then return (FormatInt(theNum div 1000,
theSeparator) & theSeparator & text
-3 thru -1 of ("00" & ((theNum mod 1000) as text)))
return theNum as text
end FormatInt
FormatInt(9.99999999E+8, ",")
The example above doesn't give expected result on my system, I get
"999,999,9,0" .
From what I can see there's a problem coercing a real in
exponential form to integer, last comma is due to my locale setting.
Unfortunately "number as text" return a string that is only useful
as display text.
"10.1 as text" returns "10,1" in some european countries.
As long as the result is used for display only thats fine.
But if the result must be used for further processing the implied
coersion is inconvenient.
I would like to have something like this:
No, it's very useful !
When I treat numbers from a spreadsheet for instance, I grab the
numbers as numbers so they use the period but, when I am ready to
pass the calculated values to the sheet, I coerce as string so the
sheet receive the format which it is able to treat.
If this coercion bothers you, there is an easy workaround:
set tnum to (9.99999999999E+11) as text
set tnum to my remplace(tnum, ",", ".") (* the workaround *)
set nstr to (do shell script "tclsh <<< 'puts [expr " & tnum & "];'")
on remplace(t, d1, d2)
set AppleScript's text item delimiters to d1
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to ""
return t
end remplace
Yvan KOENIG (from FRANCE jeudi 6 novembre 2008 11:19:34)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden