Re: BIG number as string [re-round error]
Re: BIG number as string [re-round error]
- Subject: Re: BIG number as string [re-round error]
- From: Andy Wylie <email@hidden>
- Date: Sun, 22 Dec 2002 11:42:37 +1300
on Sat, 21 Dec 2002 15:03:39 +0000 julifos wrote:
>
But I still get round errors when doing the conversion (tens in E+15,
>
hundreds in E+16, thousands in E+17, ...?):
>
do you mean truncation using Deivy's handler?
I sorta I fixed that...
to ndigits(n) --> Deivy Petrescu
set myzeros to "000000000000000000000000000000000000000000"
set n to |no round big n to text|(n)
set k to (offset of "E" in n) + 1
if k = 1 then return n
set sep to (0.1 as string)'s item 2
set x to (characters (k + 1) thru -1 of n as string) as number
set zas to (character 1 of n) & (characters 3 thru (k - 2) of n) as
string
if character (k) of n is "-" then return ("0" & sep & characters 1 thru
(x - 1) of myzeros) & zas as string
--log {n, zas, k, x}
if x > 15 then
set _end to sep & "0"
else if k < 15 then
set _end to sep & character (x + 2) of (zas & myzeros)
else
set _end to sep & characters (x + 2) thru (k - 2) of (zas & myzeros)
end if
return (characters 1 thru (x + 1) of (zas & myzeros)) & _end as string
end ndigits
_____________________________ Andy
_______________________________________________
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.