I know this topic has been on the shelf a while but I was inspired to give it a go. This includes a super-simple shell script conversion of exponential numbers in line one, and then some if-thens for placing some commas when the numbers get big. The largest number it spit out during tests with the included random number generator was this…
“‘2,012,009,890,299,000,053,078,911,865,592,313,973,011,672,255,274,113,821,952,938,596,545,074,236,404,122,939,660,629,558,622,321,119,207,482,003,043,218,878,507,374,303,208,823,402,681,339,224,450,318,609,019,554,750,335,013,720,074,481,739,669,129,534,518,591,488.00’”
If there’s a good reason not to do it this way, let me know. (I should note that it currently rounds off to two spaces but that adjustable**)
------------------------GENERATE A RANDOM NUMBER------------------------
set nmbr to rndm()
on rndm()
try
set {intgrs, oprtrs} to {{1, 2, 3, 4, 5, 6, 7, 8, 9, pi}, {"+", "-", "*", "÷", "^"}}
set {a, b, c} to {some item of intgrs, some item of intgrs, some item of intgrs}
set {x, y, z} to {some item of oprtrs, some item of oprtrs, some item of oprtrs}
set scpt to " " & a & " " & x & " " & b & " " & y & " " & c & " " & z & " " & some item of {a, b, c}
set nmbr to run script scpt
on error err ----->When result is too large this error handler will unnecessarily show you the problem.
display dialog "Oops! " & err & return & scpt with title "skip this attempt!"
return my rndm()
end try
end rndm
------------------------CONVERT THE NUMBER TO READABLE TEXT------------------------
set n to do shell script "printf \"%1.2f\" " & (nmbr as text) ---This converts scientific notation to real numbers.**change the '.2' to '.3' for '.xxx', or to '.6' for '.xxxxxx', etc.
set {strng, thrd} to {"", 0}
repeat with chr in (reverse of (every character of n))
set {strng, thrd} to {chr & strng, thrd + 1}
if (length of strng) ≥ (offset of "." in ((reverse of (every character of n)) as text)) then --add commas!
if (chr as text is ".") then set thrd to 0
if (length of strng > 2) and ((characters 1 thru 2 of strng) as text) is ".," then set strng to "." & (characters 3 thru -1 of strng)
if (thrd = 3) then set {strng, thrd} to {"," & strng, 0}
end if
end repeat
if ((characters 1 thru 2 of strng) as text) is "-," then set strng to "-" & (characters 3 thru -1 of strng) as string -->prevents '-,xxx'
if character 1 of strng is "," then set strng to (characters 2 thru -1 of strng) as string -->prevents ',xxx'
return strng
Model: Mac Pro, Yosemite
AppleScript: 2.7
Browser: Safari 601.2.7
Operating System: macOS 10.14