• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert long number to string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert long number to string


  • Subject: Re: Convert long number to string
  • From: Paul Berkowitz <email@hidden>
  • Date: Sat, 17 Apr 2004 10:24:38 -0700

On 4/17/04 8:48 AM, "Gnarlodious" <email@hidden> wrote:

> I seem to recall a discussion about this recently but the archives aren't up
> and running.
>
> set longNumber to to "1082204521"
> set exponent to longNumber as number --> 1.082204521E+9
> set numberString to exponent as string --> "1.082204521E+9"
>
> I want to convert the exponent to long number before converting it to a
> string.
>
> What's the technique?

Here's my version (it works even if you have "," rather than "." set as
decimal separator):


to Stringify(X) -- for E+ numbers
set X to X as string
set {tids, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, {"E+"}}
if (count (text items of X)) = 1 then
set AppleScript's text item delimiters to {tids}
return X
else
set {n, z} to {text item 1 of X, (text item 2 of X) as integer}
set AppleScript's text item delimiters to {tids}
set i to character 1 of n
set decSepChar to character 2 of n -- "." or ","
set d to text 3 thru -1 of n
set l to count d
if l > z then
return (i & (text 1 thru z of d) & decSepChar & (text (z + 1)
thru -1 of d))
else
repeat (z - l) times
set d to d & "0"
end repeat
return (i & d)
end if
end if
end Stringify

set longNumber to "1082204521"
set exponent to longNumber as number --> 1.082204521E+9
set numberString to Stringify(exponent)
--> "1082204521"


set longNumber to "10822045.21"
set exponent to longNumber as number --> 1.082204521E+7
set numberString to Stringify(exponent)
--> "10822045.21"

set longNumber to "0.1082204521"
set exponent to longNumber as number --> 0.1082204521
set numberString to Stringify(exponent)
--> "0.1082204521"



--
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: 
 >Convert long number to string (From: Gnarlodious <email@hidden>)

  • Prev by Date: Re: Convert long number to string
  • Next by Date: Re: python
  • Previous by thread: Re: Convert long number to string
  • Next by thread: Re: Convert long number to string
  • Index(es):
    • Date
    • Thread