Re: Big numbers
Re: Big numbers
- Subject: Re: Big numbers
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 20 Apr 2003 11:46:43 -0700
On 4/20/03 11:05 AM, "Thomas C." <email@hidden> wrote:
>
Hi, I have a quiet big number and AppleScript shows me it like this :
>
2.222222222E+9
>
>
How can I get it like this :
>
2222222222
>
You can do it as a string, if that's what you want. The following works for
European-style "," decimal separators as well as "." English-style. Unwrap
long lines.
set bigNumber to my NumberToString(2.222222222E+9)
--> "2222222222"
on NumberToString(bigNumber)
set bigNumber to bigNumber as string
if bigNumber does not contain "E+" then return bigNumber
set {tids, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {"E+"}}
try
set {basicReal, powersOfTen} to {bigNumber's text item 1,
(bigNumber's text item 2) as integer}
on error -- e.g. Python strings have lower-case "e", tids case-sensitive
set AppleScript's text item delimiters to {"e+"}
set {basicReal, powersOfTen} to {bigNumber's text item 1,
(bigNumber's text item 2) as integer}
end try
set AppleScript's text item delimiters to {"."}
try
set {integerPart, decimalPart} to basicReal's {text item 1, text
item 2}
set decimalSign to "."
on error
set AppleScript's text item delimiters to {","}
set {integerPart, decimalPart} to basicReal's {text item 1, text
item 2}
set decimalSign to ","
end try
set AppleScript's text item delimiters to tids
set n to count decimalPart
if powersOfTen n then
repeat (powersOfTen - n) times
set decimalPart to decimalPart & "0"
end repeat
set bigNumber to integerPart & decimalPart
else
set bigNumber to integerPart & decimalPart
set bigNumber to text 1 thru (powersOfTen + 1) of bigNumber &
decimalSign & text (powersOfTen + 2) thru -1 of bigNumber
end if
return bigNumber
end NumberToString
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: | |
| >Big numbers (From: "Thomas C." <email@hidden>) |