
Change
How can change number to text. For example amount in invoice is 5000usd . I will see text too in down invoice. Five thousand dollars
-
I just did both and I changed my field name to Net so you don't have to change anything.
This is the code for Cents Fraction:
let empty := "";
let x := [empty, "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "];
let y := [empty, empty, "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "];
"/* ";
" * User defined functions";
" */ ";
function mod(dividend : number,divisor : number) do
dividend - divisor * floor(dividend / divisor)
end;
function numberToWord(num : number,suffix : text) do
if floor(num) != 0 then
if num > 19 then
item(y, floor(num / 10)) + item(x, mod(num, 10)) + suffix
else
item(x, num) + suffix
end
else
empty
end
end;
"/* ";
" * Main program";
" */ ";
"// Number to be converted to words";
let numAmount := Net;
"// Test for number of digits";
if length(format(floor(numAmount), "0")) < 11 then
"// String to store word representation of given number";
let NtW := "";
"// This handles Cents";
if contains(text(numAmount), ".") then
let dpIndex := index(text(numAmount), ".");
NtW := "and " + substr(text(numAmount), dpIndex + 1, 2) + "/100 usd"
end;
"// This handles digits at Ones and Tens place";
NtW := numberToWord(mod(numAmount, 100), "") + NtW;
"// This handles digit at Hundreds place";
NtW := numberToWord(mod(numAmount / 100, 10), "Hundred ") + NtW;
"// This handles digits at One Thousands and Ten Thousands place";
NtW := numberToWord(mod(numAmount / 1000, 100), "Thousand ") + NtW;
"// This handles digit at Hundred Thousands place";
NtW := numberToWord(mod(numAmount / 100000, 10), "Hundred ") + NtW;
"// This handles digits at One Millions and Ten Millions place";
NtW := numberToWord(mod(numAmount / 1000000, 100), "Million ") + NtW;
"// This handles digit at Hundred Millions place";
NtW := numberToWord(mod(numAmount / 100000000, 10), "Hundred ") + NtW;
"// This handles digit at One Billions place";
NtW := numberToWord(mod(numAmount / 1000000000, 10), "Billion ") + NtW;
NtW
else
"Number is too large"
end -
This is the code for Cents Words:
let empty := "";
let x := [empty, "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "];
let y := [empty, empty, "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "];
"/* ";
" * User defined functions";
" */ ";
function mod(dividend : number,divisor : number) do
dividend - divisor * floor(dividend / divisor)
end;
function numberToWord(num : number,suffix : text) do
if floor(num) != 0 then
if num > 19 then
item(y, floor(num / 10)) + item(x, mod(num, 10)) + suffix
else
item(x, num) + suffix
end
else
empty
end
end;
"/* ";
" * Main program";
" */ ";
"// Number to be converted to words";
let numAmount := Net;
"// Test for number of digits";
if length(format(floor(numAmount), "0")) < 11 then
"// String to store word representation of given number";
let NtW := "";
"// This handles Cents";
if contains(text(numAmount), ".") then
let dpIndex := index(text(numAmount), ".");
let numCents := number(substr(text(numAmount), dpIndex + 1, 2));
NtW := "and " + numberToWord(mod(numCents, 100), "Cents") + " usd"
end;
"// This handles digits at Ones and Tens place";
NtW := numberToWord(mod(numAmount, 100), "") + NtW;
"// This handles digit at Hundreds place";
NtW := numberToWord(mod(numAmount / 100, 10), "Hundred ") + NtW;
"// This handles digits at One Thousands and Ten Thousands place";
NtW := numberToWord(mod(numAmount / 1000, 100), "Thousand ") + NtW;
"// This handles digit at Hundred Thousands place";
NtW := numberToWord(mod(numAmount / 100000, 10), "Hundred ") + NtW;
"// This handles digits at One Millions and Ten Millions place";
NtW := numberToWord(mod(numAmount / 1000000, 100), "Million ") + NtW;
"// This handles digit at Hundred Millions place";
NtW := numberToWord(mod(numAmount / 100000000, 10), "Hundred ") + NtW;
"// This handles digit at One Billions place";
NtW := numberToWord(mod(numAmount / 1000000000, 10), "Billion ") + NtW;
NtW
else
"Number is too large"
end -
This should take care of that problem. It also checks for 0 cents so the "and" won't be displayed in that case.
let empty := "";
let x := [empty, "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "];
let y := [empty, empty, "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "];
"/* ";
" * User defined functions";
" */ ";
function mod(dividend : number,divisor : number) do
dividend - divisor * floor(dividend / divisor)
end;
function numberToWord(num : number,suffix : text) do
if floor(num) != 0 then
if floor(num) > 19 then
item(y, floor(num / 10)) + item(x, mod(num, 10)) + suffix
else
item(x, num) + suffix
end
else
empty
end
end;
"/* ";
" * Main program";
" */ ";
"// Number to be converted to words";
let numAmount := Net;
"// Test for number of digits";
if length(format(floor(numAmount), "0")) < 11 then
"// String to store word representation of given number";
let NtW := "";
"// This handles Cents";
if contains(text(numAmount), ".") then
let dpIndex := index(text(numAmount), ".");
let numCents := number(substr(text(numAmount), dpIndex + 1, 2));
if numCents > 0 then
NtW := "and " + numberToWord(mod(numCents, 100), "Cents") + " usd"
else
NtW := "usd"
end
end;
"// This handles digits at Ones and Tens place";
NtW := numberToWord(mod(numAmount, 100), "") + NtW;
"// This handles digit at Hundreds place";
NtW := numberToWord(mod(numAmount / 100, 10), "Hundred ") + NtW;
"// This handles digits at One Thousands and Ten Thousands place";
NtW := numberToWord(mod(numAmount / 1000, 100), "Thousand ") + NtW;
"// This handles digit at Hundred Thousands place";
NtW := numberToWord(mod(numAmount / 100000, 10), "Hundred ") + NtW;
"// This handles digits at One Millions and Ten Millions place";
NtW := numberToWord(mod(numAmount / 1000000, 100), "Million ") + NtW;
"// This handles digit at Hundred Millions place";
NtW := numberToWord(mod(numAmount / 100000000, 10), "Hundred ") + NtW;
"// This handles digit at One Billions place";
NtW := numberToWord(mod(numAmount / 1000000000, 10), "Billion ") + NtW;
NtW
else
"Number is too large"
end -
This code adjusts for Euros and tests for 0.00
let empty := "";
let x := [empty, "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "];
let y := [empty, empty, "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "];
"/* ";
" * User defined functions";
" */ ";
function mod(dividend : number,divisor : number) do
dividend - divisor * floor(dividend / divisor)
end;
function numberToWord(num : number,suffix : text) do
if floor(num) != 0 then
if floor(num) > 19 then
item(y, floor(num / 10)) + item(x, mod(num, 10)) + suffix
else
item(x, num) + suffix
end
else
empty
end
end;
"/* ";
" * Main program";
" */ ";
"// Number to be converted to words";
let numAmount := Net;
"// Test for number of digits";
if length(format(floor(numAmount), "0")) < 11 then
"// String to store word representation of given number";
let NtW := "";
"// This handles Cents";
if contains(text(numAmount), ".") then
let dpIndex := index(text(numAmount), ".");
let numCents := number(substr(text(numAmount), dpIndex + 1, 2));
if floor(numAmount) > 0 then NtW := "and " end;
if numCents > 0 then
NtW := NtW + numberToWord(mod(numCents, 100), "Cents")
else
if floor(numAmount) > 0 then
NtW := NtW + "no Cents"
else
NtW := ""
end
end
end;
if floor(numAmount) > 0 then NtW := "Euro " + NtW end;
"// This handles digits at Ones and Tens place";
NtW := numberToWord(mod(numAmount, 100), "") + NtW;
"// This handles digit at Hundreds place";
NtW := numberToWord(mod(numAmount / 100, 10), "Hundred ") + NtW;
"// This handles digits at One Thousands and Ten Thousands place";
NtW := numberToWord(mod(numAmount / 1000, 100), "Thousand ") + NtW;
"// This handles digit at Hundred Thousands place";
NtW := numberToWord(mod(numAmount / 100000, 10), "Hundred ") + NtW;
"// This handles digits at One Millions and Ten Millions place";
NtW := numberToWord(mod(numAmount / 1000000, 100), "Million ") + NtW;
"// This handles digit at Hundred Millions place";
NtW := numberToWord(mod(numAmount / 100000000, 10), "Hundred ") + NtW;
"// This handles digit at One Billions place";
NtW := numberToWord(mod(numAmount / 1000000000, 10), "Billion ") + NtW;
NtW
else
"Number is too large"
end -
Good day,
At the moment i use Euro. I use two decimas. fot thausand seperator i use "," but i supose that ninox takes that from macbook setings. i changed the seperator sign in formula and it works well now. just wondering is is posible to show thausiand hundres etc in words and cents in numbers ex (Two thausiand eight huntret thirty euro and 57 cent ). as in my countrys ammount in words should be in this order.
-
Can't see the forest for the trees department... Since Ninox does not store numbers with a "," as a decimal separator, you would be converting from a number that already exists in your database, right? You could just use that number in the Number to Words code. If it is the result of a calculation, you can just change:
let numAmount := Net;
to: let numAmount := yourCalculation
-
Hi Nick,
I'm happy to contribute. Do the non-English versions of Ninox allow the storage of numbers using "," as the decimal separator? If so, what is the thousands, or grouping, separator? If the grouping separator is not the same as the decimal separator, it should be an easy fix. Otherwise, I'll need to figure out a different way to separate integers from decimals.
The most recent version of the code is posted on page 5 and it does not display cents as a fraction. Also, what is more common Euro or Euros for plural? I did search on that topic and there does not appear to be a consensus in that regard. I'll be driving most of the day so I won't be able to respond until later.
Sean