Re: Number to words [Re: Excel & AppleScripting]
Re: Number to words [Re: Excel & AppleScripting]
- Subject: Re: Number to words [Re: Excel & AppleScripting]
- From: "Nigel Garvey" <email@hidden>
- Date: Wed, 10 Feb 2010 23:00:24 +0000
"Nigel Garvey" wrote on Wed, 10 Feb 2010 16:08:16 +0000:
>"Stockly, Ed" wrote on Mon, 8 Feb 2010 10:46:40 -0800:
>
>>on NumberToWords(aNum)
>
>That idea struck me as a pleasant way to waste an evening. :)
The following section of the script I posted doesn't render fractional
numbers between -1 and 1 in quite the way I want. (It omits the "zero"
from results like "zero point five".)
> -- Main handler code. Set up.
> if (n is 0) then
> -- Special-case 0.
> set end of o's collector to "zero"
> else
> -- Adjust if negative.
> if (n < 0) then
> set end of o's collector to "minus"
> set n to -n
> end if
>
> -- Analyse language parameter.
> set o's longScale to (lang ends with "GB")
> if (result) then set o's landmarks to o's longScaleLandmarks
> set o's usingAnd to (lang does not end with "US")
>
> -- Deal with the non-fractional part of the number.
> o's parseNumber(n div 1, 0)
>
> -- Deal with any fractional part.
> -- (Vulnerable to floating-point errors.)
> if (n mod 1 > 0.0) then
> set end of o's collector to "point"
> set n to n * 10
> repeat
> set u to n mod 10 div 1
> if (u is 0) then
> set end of o's collector to "zero"
> else
> set end of o's collector to item (u div 1) of o's unitsAndTeens
> end if
> set n to n * 10
> if (n mod 10 is 0.0) then exit repeat
> end repeat
> end if
> end if
It needs to be rearranged thus:
-- Main handler code. Set up.
-- Adjust if negative.
if (n < 0) then
set end of o's collector to "minus"
set n to -n
end if
if (n div 1 is 0) then
-- Special-case 0.
set end of o's collector to "zero"
else
-- Analyse language parameter.
set o's longScale to (lang ends with "GB")
if (result) then set o's landmarks to o's longScaleLandmarks
set o's usingAnd to (lang does not end with "US")
-- Deal with the non-fractional part of the number.
o's parseNumber(n div 1, 0)
end if
-- Deal with any fractional part.
-- (Vulnerable to floating-point errors.)
if (n mod 1 > 0.0) then
set end of o's collector to "point"
set n to n * 10
repeat
set u to n mod 10 div 1
if (u is 0) then
set end of o's collector to "zero"
else
set end of o's collector to item (u div 1) of o's unitsAndTeens
end if
set n to n * 10
if (n mod 10 is 0.0) then exit repeat
end repeat
end if
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden