Re: Convert long number to string
Re: Convert long number to string
- Subject: Re: Convert long number to string
- From: Martin Orpen <email@hidden>
- Date: Sat, 17 Apr 2004 17:52:41 +0100
on 17/4/04 4:48 pm, Gnarlodious at 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?
You can use "as inches as string":
set longNumber to "1082204521"
set exponent to longNumber as number
set realNumber to (exponent * 3) as inches as string --> "3246613563"
AS is a pain with *big* numbers.
I've been messing about with using "bc" recently while helping my eldest
daughter with her maths homework:
set myInteger to (text returned of (display dialog "Enter a number to
check for primeness:" default answer ""))
set intList to {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
set x to 2
set resultList to {}
repeat 5 times
set myPower to do shell script "echo 'scale=1; ((" & x & "^" &
myInteger & ") -" & x & ")/" & myInteger & "' | bc"
set end of resultList to myPower
set x to x + 1
end repeat
set myCheck to {}
repeat with i in resultList
set end of myCheck to last item of i
end repeat
set y to 1
if myCheck is {"0", "0", "0", "0", "0"} then
repeat with theFactor from 3 to (2 * ((myInteger ^ 0.5) div 2) + 3) by
2
if (myInteger mod theFactor) = 0 then
set y to 2
end if
end repeat
if y is not 2 then
display dialog (myInteger as string) & " is a prime number." & "
(Fermat test tenths: " & (myCheck as string) & ")"
else
display dialog (myInteger as string) & " Is a Carmichael Number -
it passes the Fermat test but fails a brute force check." & " (Fermat test
tenths: " & (myCheck as string) & ")"
end if
else
if item 1 of myCheck is "0" then
display dialog (myInteger as string) & " is a pseudoprime." & "
(Fermat test tenths: " & (myCheck as string) & ")"
else
display dialog (myInteger as string) & " is not prime." & " (Fermat
test tenths: " & (myCheck as string) & ")"
end if
end if
Regards
--
Martin Orpen
Idea Digital Imaging Ltd -- The Image Specialists
http://www.idea-digital.com
_______________________________________________
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.