Anonymous user
Number names: Difference between revisions
Undo revision 77936 by Demivec (Talk)
(→{{header|PureBasic}}: Increased the range of accepted numbers (!!!)) |
|||
Line 861:
print num2en(123456789), "\n";</lang>
=={{header|PureBasic}}==
<lang PureBasic>DataSection
numberNames:
Line 869 ⟶ 868:
;tens
Data.s "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"
;big, non-Chuquet system
Data.s "thousand", "million", "billion", "trillion", "quadrillion", "quintillion
EndDataSection
Procedure.s numberWords(number.
;handles
Static isInitialized = #False
Static Dim small.s(19)
Static Dim tens.s(9)
Static Dim big.s(
If Not isInitialized
Line 890 ⟶ 887:
Read.s tens(i)
Next
For i = 1 To
Read.s big(i)
Next
Line 896 ⟶ 893:
EndIf
ProcedureReturn "zero"
EndIf
▲ If Len(number) > 45
▲ Protected num.s = number, output.s, unit, unitOutput.s, working
Repeat
working =
unitOutput = ""
Select working
Line 934 ⟶ 913:
EndSelect
working =
If working
If unitOutput <> ""
Line 952 ⟶ 931:
output = unitOutput + output
Until num =
If
output = "negative " + output
EndIf
Line 967 ⟶ 942:
EndProcedure
If OpenConsole()
PrintN(Str(1234567890) + " = " + numberWords(1234567890) + #CRLF$)
PrintN(Str(-987654321) + " = " + numberWords(-987654321) + #CRLF$)
PrintN(Str(900000000001) + " = " + numberWords(900000000001) + #CRLF$)
PrintN(Str(9223372036854775807) + " = " + numberWords(9223372036854775807) + #CRLF$)
n$ = Input()▼
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
▲ PrintN(numberWords(n$))
CloseConsole()
EndIf</lang>
Sample output (reformatted here for an 80 column display):
<pre>1234567890 = one billion, two hundred thirty-four million,
five hundred sixty-seven thousand, eight hundred ninety
-987654321 = negative nine hundred eighty-seven million,
900000000001 = nine hundred billion, one
three hundred seventy-two trillion, thirty-six billion,
eight hundred fifty-four million, seven hundred seventy-five thousand,
eight hundred seven
0 = zero</pre>
== {{header|Python}} ==
|