Convert numbers to words, e.g., 111 = one hundred eleven, using the “Indian numbering systemâ€
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
May I know if there is method for typesetting numbers to words using LaTeX. I have created an invoice in which I would like to convert the invoice amount to words. E.g., "1,23,456.00" should be typeset as "One Lakh Twenty Three Thousand Four Hundred Fifty Six Only".
Thanks a lot in advance ~
numbering strings
add a comment |Â
up vote
8
down vote
favorite
May I know if there is method for typesetting numbers to words using LaTeX. I have created an invoice in which I would like to convert the invoice amount to words. E.g., "1,23,456.00" should be typeset as "One Lakh Twenty Three Thousand Four Hundred Fifty Six Only".
Thanks a lot in advance ~
numbering strings
1
Welcome to TeX.SX! For me, your number sounds strange (I would think of it as123,456.00
and "one hundred twenty-three thousand four hundred fifty-six [unit] zero [smaller unit]" to remove some edge cases). Could you please make a small example of what you have tried (MWE)?
– TeXnician
Sep 1 at 13:51
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
May I know if there is method for typesetting numbers to words using LaTeX. I have created an invoice in which I would like to convert the invoice amount to words. E.g., "1,23,456.00" should be typeset as "One Lakh Twenty Three Thousand Four Hundred Fifty Six Only".
Thanks a lot in advance ~
numbering strings
May I know if there is method for typesetting numbers to words using LaTeX. I have created an invoice in which I would like to convert the invoice amount to words. E.g., "1,23,456.00" should be typeset as "One Lakh Twenty Three Thousand Four Hundred Fifty Six Only".
Thanks a lot in advance ~
numbering strings
edited Sep 2 at 10:46


Mico
262k30354729
262k30354729
asked Sep 1 at 13:47
Ashish
441
441
1
Welcome to TeX.SX! For me, your number sounds strange (I would think of it as123,456.00
and "one hundred twenty-three thousand four hundred fifty-six [unit] zero [smaller unit]" to remove some edge cases). Could you please make a small example of what you have tried (MWE)?
– TeXnician
Sep 1 at 13:51
add a comment |Â
1
Welcome to TeX.SX! For me, your number sounds strange (I would think of it as123,456.00
and "one hundred twenty-three thousand four hundred fifty-six [unit] zero [smaller unit]" to remove some edge cases). Could you please make a small example of what you have tried (MWE)?
– TeXnician
Sep 1 at 13:51
1
1
Welcome to TeX.SX! For me, your number sounds strange (I would think of it as
123,456.00
and "one hundred twenty-three thousand four hundred fifty-six [unit] zero [smaller unit]" to remove some edge cases). Could you please make a small example of what you have tried (MWE)?– TeXnician
Sep 1 at 13:51
Welcome to TeX.SX! For me, your number sounds strange (I would think of it as
123,456.00
and "one hundred twenty-three thousand four hundred fifty-six [unit] zero [smaller unit]" to remove some edge cases). Could you please make a small example of what you have tried (MWE)?– TeXnician
Sep 1 at 13:51
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
11
down vote
Here's an easy version spelling out currencies (as an example with Euros). Please note that you have to input the number and its decimal places separately.
documentclassarticle
usepackagenumname
newcommandmajorUnitEuros
newcommandminorUnitCents
newcommandspellOutCurrency[2]%
NumToName#1,majorUnit and NumToName#2,minorUnit%
begindocument
spellOutCurrency12345600
enddocument
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
@EthanBolker That might be, but I have not written this (that "and" is fixed innumname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.
– TeXnician
Sep 1 at 15:54
5
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
The "and" string can be suppressed by executingrenewcommand*namenumberand
after loading thenumname
package. Commas and dashes may be suppressed as well.
– Mico
Sep 2 at 10:57
add a comment |Â
up vote
9
down vote
(updated the answer to allow for fractional parts in the numbers as well as for very large numbers (>10^12))
Here's a LuaLaTeX-based solution that expresses numbers in words while using the so-called Indian numbering system. This system uses multiples of lakh (10^5
), crore (10^7
), and lakh crore (10^12
) instead of million, billion, and trillion to denote large numbers.
The code consists of 2 Lua utility functions, a Lua function called num2word
, and a LaTeX macro called numtoword
, which is just a front-end or "wrapper" for the num2word
function. The argument of numtoword
must be either a positive number or an expression that evaluates to a positive number under the usual rules of Lua syntax, e.g., 1+1+1
, 2e7
, and 3*10^5
. Commas are not allowed in the input of numtoword
. I.e., don't write num2word1,000,000
("Western" system) or numtoword10,00,000
("Indian" system), Instead, write num2word1000000
or num2word1e6
.
If the number contains a fractional part, the fractional part is rounded automatically to 2 digits. Most modern currencies I'm familiar contain a "cent" component, i.e., a fractional part that is a multiple of 0.01
.
If the number is smaller than 1 lakh (10^5) and if the number's fractional part equals 0, the suffix "Only" is appended to the word string; if the number's fractional part is nonzero, its word-equivalent (using "Hundredths") is appended. Finally, if the number is either exactly equal to 0 or is a large integer (>=1e5) which consists only of lakh, crore, and/or lakh crore (but no ten-thousands component), the "Only" suffix is not appended.
% !TEX TS-program = lualatex
documentclassarticle
usepackagegeometry % optional
usepackagefancyvrb % for "Verb" macro
usepackagenumname % for "NumToName" macro
% Modify some of the macros of the 'numname' package
renewcommand*namenumbercomma % default: ", "
renewcommand*tensunitsep % default: "-"
renewcommand*namenumberand % default: " and "
usepackageluacode % for "luacode" environment
beginluacode
-- Utility function: Round number to nearest integer
function math.round ( x )
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
-- Typeset non-integer part of the number
function displaycents ( c , flag )
-- value of 'flag' can be either '1' or '0'
if flag==1 then
if c==0 then
tex.sprint ( " Only" )
elseif c==1 then
tex.sprint ( " and One Hundreth" )
else
tex.sprint ( " and \NumToName" .. c .. " Hundreths" )
end
elseif flag==0 then
if c==0 then
tex.sprint ( "Zero" )
elseif c==1 then
tex.sprint ( "One Hundreth" )
else
tex.sprint ( "\NumToName" .. c .. " Hundreths" )
end
end
end
-- 'num2name' is the main lua function
function num2name ( n )
local cents, lakhcrore, crore, lakh, rem
-- Retrieve decimal and integer parts of 'n'
cents = math.round ( 100 * ( n-math.floor(n) ) )
n = math.floor ( n ) -- integer part
-- calculate number of lakh crore, crore, lakh, and rem
lakhcrore = math.floor ( n / 1e12 ) -- lakh crore
crore = math.floor ( (n % 1e12) / 1e7 )-- crore
lakh = math.floor ( (n % 1e7) / 1e5 ) -- lakh
rem = n % 1e5 -- remainder
if n>0 then -- number >= 1.00
if lakhcrore>0 then
if crore==0 then
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh Crore" )
else
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh" )
end
if crore>0 or lakh>0 or rem>0 then tex.sprint (" ") end
end
if crore>0 then
tex.sprint ( "\NumToName" .. crore .. " Crore" )
if lakh>0 or rem>0 then tex.sprint (" ") end
end
if lakh>0 then
tex.sprint ( "\NumToName" .. lakh .. " Lakh" )
if rem>0 then tex.sprint (" ") end
end
if rem>0 then
tex.sprint ( "\NumToName" .. rem .. "" )
-- display fractional part ("cents")
displaycents ( cents , 1 )
end
else -- 0 <= number <= 0.99
displaycents ( cents , 0 )
end
end
endluacode
%% LaTeX wrapper macro:
newcommandnumtoword[1]directluanum2name(#1)
begindocument
noindent
begintabular@ll@
Verb:10^5: & numtoword10^5 \
Verb:2e7: & numtoword2e7 \
Verb:3e12: & numtoword3e12 \
Verb:6789e8: & numtoword6789e10 \
Verb:456e5: & numtoword456e5 \
Verb:123456:& numtoword123456 \
Verb:123456.78: & numtoword123450+6.78 \
Verb:1: & numtoword1 \
Verb:0: & numtoword0 \
Verb:0.01: & numtoword0.01 \
Verb:0.51: & numtoword0.51 \
endtabular
enddocument
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
Here's an easy version spelling out currencies (as an example with Euros). Please note that you have to input the number and its decimal places separately.
documentclassarticle
usepackagenumname
newcommandmajorUnitEuros
newcommandminorUnitCents
newcommandspellOutCurrency[2]%
NumToName#1,majorUnit and NumToName#2,minorUnit%
begindocument
spellOutCurrency12345600
enddocument
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
@EthanBolker That might be, but I have not written this (that "and" is fixed innumname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.
– TeXnician
Sep 1 at 15:54
5
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
The "and" string can be suppressed by executingrenewcommand*namenumberand
after loading thenumname
package. Commas and dashes may be suppressed as well.
– Mico
Sep 2 at 10:57
add a comment |Â
up vote
11
down vote
Here's an easy version spelling out currencies (as an example with Euros). Please note that you have to input the number and its decimal places separately.
documentclassarticle
usepackagenumname
newcommandmajorUnitEuros
newcommandminorUnitCents
newcommandspellOutCurrency[2]%
NumToName#1,majorUnit and NumToName#2,minorUnit%
begindocument
spellOutCurrency12345600
enddocument
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
@EthanBolker That might be, but I have not written this (that "and" is fixed innumname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.
– TeXnician
Sep 1 at 15:54
5
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
The "and" string can be suppressed by executingrenewcommand*namenumberand
after loading thenumname
package. Commas and dashes may be suppressed as well.
– Mico
Sep 2 at 10:57
add a comment |Â
up vote
11
down vote
up vote
11
down vote
Here's an easy version spelling out currencies (as an example with Euros). Please note that you have to input the number and its decimal places separately.
documentclassarticle
usepackagenumname
newcommandmajorUnitEuros
newcommandminorUnitCents
newcommandspellOutCurrency[2]%
NumToName#1,majorUnit and NumToName#2,minorUnit%
begindocument
spellOutCurrency12345600
enddocument
Here's an easy version spelling out currencies (as an example with Euros). Please note that you have to input the number and its decimal places separately.
documentclassarticle
usepackagenumname
newcommandmajorUnitEuros
newcommandminorUnitCents
newcommandspellOutCurrency[2]%
NumToName#1,majorUnit and NumToName#2,minorUnit%
begindocument
spellOutCurrency12345600
enddocument
answered Sep 1 at 14:02


TeXnician
20.5k52880
20.5k52880
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
@EthanBolker That might be, but I have not written this (that "and" is fixed innumname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.
– TeXnician
Sep 1 at 15:54
5
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
The "and" string can be suppressed by executingrenewcommand*namenumberand
after loading thenumname
package. Commas and dashes may be suppressed as well.
– Mico
Sep 2 at 10:57
add a comment |Â
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
@EthanBolker That might be, but I have not written this (that "and" is fixed innumname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.
– TeXnician
Sep 1 at 15:54
5
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
The "and" string can be suppressed by executingrenewcommand*namenumberand
after loading thenumname
package. Commas and dashes may be suppressed as well.
– Mico
Sep 2 at 10:57
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
Careful about the "ands". I think 456 is just "four hundred fifty six".
– Ethan Bolker
Sep 1 at 15:50
@EthanBolker That might be, but I have not written this (that "and" is fixed in
numname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.– TeXnician
Sep 1 at 15:54
@EthanBolker That might be, but I have not written this (that "and" is fixed in
numname
). As the OP did not specify his exact needs I will leave the answer as simple as possible.– TeXnician
Sep 1 at 15:54
5
5
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
@EthanBolker The UK and the US have different conventions regarding the use of "and" when spelling out numbers.
– Peter Wilson
Sep 1 at 17:52
The "and" string can be suppressed by executing
renewcommand*namenumberand
after loading the numname
package. Commas and dashes may be suppressed as well.– Mico
Sep 2 at 10:57
The "and" string can be suppressed by executing
renewcommand*namenumberand
after loading the numname
package. Commas and dashes may be suppressed as well.– Mico
Sep 2 at 10:57
add a comment |Â
up vote
9
down vote
(updated the answer to allow for fractional parts in the numbers as well as for very large numbers (>10^12))
Here's a LuaLaTeX-based solution that expresses numbers in words while using the so-called Indian numbering system. This system uses multiples of lakh (10^5
), crore (10^7
), and lakh crore (10^12
) instead of million, billion, and trillion to denote large numbers.
The code consists of 2 Lua utility functions, a Lua function called num2word
, and a LaTeX macro called numtoword
, which is just a front-end or "wrapper" for the num2word
function. The argument of numtoword
must be either a positive number or an expression that evaluates to a positive number under the usual rules of Lua syntax, e.g., 1+1+1
, 2e7
, and 3*10^5
. Commas are not allowed in the input of numtoword
. I.e., don't write num2word1,000,000
("Western" system) or numtoword10,00,000
("Indian" system), Instead, write num2word1000000
or num2word1e6
.
If the number contains a fractional part, the fractional part is rounded automatically to 2 digits. Most modern currencies I'm familiar contain a "cent" component, i.e., a fractional part that is a multiple of 0.01
.
If the number is smaller than 1 lakh (10^5) and if the number's fractional part equals 0, the suffix "Only" is appended to the word string; if the number's fractional part is nonzero, its word-equivalent (using "Hundredths") is appended. Finally, if the number is either exactly equal to 0 or is a large integer (>=1e5) which consists only of lakh, crore, and/or lakh crore (but no ten-thousands component), the "Only" suffix is not appended.
% !TEX TS-program = lualatex
documentclassarticle
usepackagegeometry % optional
usepackagefancyvrb % for "Verb" macro
usepackagenumname % for "NumToName" macro
% Modify some of the macros of the 'numname' package
renewcommand*namenumbercomma % default: ", "
renewcommand*tensunitsep % default: "-"
renewcommand*namenumberand % default: " and "
usepackageluacode % for "luacode" environment
beginluacode
-- Utility function: Round number to nearest integer
function math.round ( x )
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
-- Typeset non-integer part of the number
function displaycents ( c , flag )
-- value of 'flag' can be either '1' or '0'
if flag==1 then
if c==0 then
tex.sprint ( " Only" )
elseif c==1 then
tex.sprint ( " and One Hundreth" )
else
tex.sprint ( " and \NumToName" .. c .. " Hundreths" )
end
elseif flag==0 then
if c==0 then
tex.sprint ( "Zero" )
elseif c==1 then
tex.sprint ( "One Hundreth" )
else
tex.sprint ( "\NumToName" .. c .. " Hundreths" )
end
end
end
-- 'num2name' is the main lua function
function num2name ( n )
local cents, lakhcrore, crore, lakh, rem
-- Retrieve decimal and integer parts of 'n'
cents = math.round ( 100 * ( n-math.floor(n) ) )
n = math.floor ( n ) -- integer part
-- calculate number of lakh crore, crore, lakh, and rem
lakhcrore = math.floor ( n / 1e12 ) -- lakh crore
crore = math.floor ( (n % 1e12) / 1e7 )-- crore
lakh = math.floor ( (n % 1e7) / 1e5 ) -- lakh
rem = n % 1e5 -- remainder
if n>0 then -- number >= 1.00
if lakhcrore>0 then
if crore==0 then
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh Crore" )
else
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh" )
end
if crore>0 or lakh>0 or rem>0 then tex.sprint (" ") end
end
if crore>0 then
tex.sprint ( "\NumToName" .. crore .. " Crore" )
if lakh>0 or rem>0 then tex.sprint (" ") end
end
if lakh>0 then
tex.sprint ( "\NumToName" .. lakh .. " Lakh" )
if rem>0 then tex.sprint (" ") end
end
if rem>0 then
tex.sprint ( "\NumToName" .. rem .. "" )
-- display fractional part ("cents")
displaycents ( cents , 1 )
end
else -- 0 <= number <= 0.99
displaycents ( cents , 0 )
end
end
endluacode
%% LaTeX wrapper macro:
newcommandnumtoword[1]directluanum2name(#1)
begindocument
noindent
begintabular@ll@
Verb:10^5: & numtoword10^5 \
Verb:2e7: & numtoword2e7 \
Verb:3e12: & numtoword3e12 \
Verb:6789e8: & numtoword6789e10 \
Verb:456e5: & numtoword456e5 \
Verb:123456:& numtoword123456 \
Verb:123456.78: & numtoword123450+6.78 \
Verb:1: & numtoword1 \
Verb:0: & numtoword0 \
Verb:0.01: & numtoword0.01 \
Verb:0.51: & numtoword0.51 \
endtabular
enddocument
add a comment |Â
up vote
9
down vote
(updated the answer to allow for fractional parts in the numbers as well as for very large numbers (>10^12))
Here's a LuaLaTeX-based solution that expresses numbers in words while using the so-called Indian numbering system. This system uses multiples of lakh (10^5
), crore (10^7
), and lakh crore (10^12
) instead of million, billion, and trillion to denote large numbers.
The code consists of 2 Lua utility functions, a Lua function called num2word
, and a LaTeX macro called numtoword
, which is just a front-end or "wrapper" for the num2word
function. The argument of numtoword
must be either a positive number or an expression that evaluates to a positive number under the usual rules of Lua syntax, e.g., 1+1+1
, 2e7
, and 3*10^5
. Commas are not allowed in the input of numtoword
. I.e., don't write num2word1,000,000
("Western" system) or numtoword10,00,000
("Indian" system), Instead, write num2word1000000
or num2word1e6
.
If the number contains a fractional part, the fractional part is rounded automatically to 2 digits. Most modern currencies I'm familiar contain a "cent" component, i.e., a fractional part that is a multiple of 0.01
.
If the number is smaller than 1 lakh (10^5) and if the number's fractional part equals 0, the suffix "Only" is appended to the word string; if the number's fractional part is nonzero, its word-equivalent (using "Hundredths") is appended. Finally, if the number is either exactly equal to 0 or is a large integer (>=1e5) which consists only of lakh, crore, and/or lakh crore (but no ten-thousands component), the "Only" suffix is not appended.
% !TEX TS-program = lualatex
documentclassarticle
usepackagegeometry % optional
usepackagefancyvrb % for "Verb" macro
usepackagenumname % for "NumToName" macro
% Modify some of the macros of the 'numname' package
renewcommand*namenumbercomma % default: ", "
renewcommand*tensunitsep % default: "-"
renewcommand*namenumberand % default: " and "
usepackageluacode % for "luacode" environment
beginluacode
-- Utility function: Round number to nearest integer
function math.round ( x )
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
-- Typeset non-integer part of the number
function displaycents ( c , flag )
-- value of 'flag' can be either '1' or '0'
if flag==1 then
if c==0 then
tex.sprint ( " Only" )
elseif c==1 then
tex.sprint ( " and One Hundreth" )
else
tex.sprint ( " and \NumToName" .. c .. " Hundreths" )
end
elseif flag==0 then
if c==0 then
tex.sprint ( "Zero" )
elseif c==1 then
tex.sprint ( "One Hundreth" )
else
tex.sprint ( "\NumToName" .. c .. " Hundreths" )
end
end
end
-- 'num2name' is the main lua function
function num2name ( n )
local cents, lakhcrore, crore, lakh, rem
-- Retrieve decimal and integer parts of 'n'
cents = math.round ( 100 * ( n-math.floor(n) ) )
n = math.floor ( n ) -- integer part
-- calculate number of lakh crore, crore, lakh, and rem
lakhcrore = math.floor ( n / 1e12 ) -- lakh crore
crore = math.floor ( (n % 1e12) / 1e7 )-- crore
lakh = math.floor ( (n % 1e7) / 1e5 ) -- lakh
rem = n % 1e5 -- remainder
if n>0 then -- number >= 1.00
if lakhcrore>0 then
if crore==0 then
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh Crore" )
else
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh" )
end
if crore>0 or lakh>0 or rem>0 then tex.sprint (" ") end
end
if crore>0 then
tex.sprint ( "\NumToName" .. crore .. " Crore" )
if lakh>0 or rem>0 then tex.sprint (" ") end
end
if lakh>0 then
tex.sprint ( "\NumToName" .. lakh .. " Lakh" )
if rem>0 then tex.sprint (" ") end
end
if rem>0 then
tex.sprint ( "\NumToName" .. rem .. "" )
-- display fractional part ("cents")
displaycents ( cents , 1 )
end
else -- 0 <= number <= 0.99
displaycents ( cents , 0 )
end
end
endluacode
%% LaTeX wrapper macro:
newcommandnumtoword[1]directluanum2name(#1)
begindocument
noindent
begintabular@ll@
Verb:10^5: & numtoword10^5 \
Verb:2e7: & numtoword2e7 \
Verb:3e12: & numtoword3e12 \
Verb:6789e8: & numtoword6789e10 \
Verb:456e5: & numtoword456e5 \
Verb:123456:& numtoword123456 \
Verb:123456.78: & numtoword123450+6.78 \
Verb:1: & numtoword1 \
Verb:0: & numtoword0 \
Verb:0.01: & numtoword0.01 \
Verb:0.51: & numtoword0.51 \
endtabular
enddocument
add a comment |Â
up vote
9
down vote
up vote
9
down vote
(updated the answer to allow for fractional parts in the numbers as well as for very large numbers (>10^12))
Here's a LuaLaTeX-based solution that expresses numbers in words while using the so-called Indian numbering system. This system uses multiples of lakh (10^5
), crore (10^7
), and lakh crore (10^12
) instead of million, billion, and trillion to denote large numbers.
The code consists of 2 Lua utility functions, a Lua function called num2word
, and a LaTeX macro called numtoword
, which is just a front-end or "wrapper" for the num2word
function. The argument of numtoword
must be either a positive number or an expression that evaluates to a positive number under the usual rules of Lua syntax, e.g., 1+1+1
, 2e7
, and 3*10^5
. Commas are not allowed in the input of numtoword
. I.e., don't write num2word1,000,000
("Western" system) or numtoword10,00,000
("Indian" system), Instead, write num2word1000000
or num2word1e6
.
If the number contains a fractional part, the fractional part is rounded automatically to 2 digits. Most modern currencies I'm familiar contain a "cent" component, i.e., a fractional part that is a multiple of 0.01
.
If the number is smaller than 1 lakh (10^5) and if the number's fractional part equals 0, the suffix "Only" is appended to the word string; if the number's fractional part is nonzero, its word-equivalent (using "Hundredths") is appended. Finally, if the number is either exactly equal to 0 or is a large integer (>=1e5) which consists only of lakh, crore, and/or lakh crore (but no ten-thousands component), the "Only" suffix is not appended.
% !TEX TS-program = lualatex
documentclassarticle
usepackagegeometry % optional
usepackagefancyvrb % for "Verb" macro
usepackagenumname % for "NumToName" macro
% Modify some of the macros of the 'numname' package
renewcommand*namenumbercomma % default: ", "
renewcommand*tensunitsep % default: "-"
renewcommand*namenumberand % default: " and "
usepackageluacode % for "luacode" environment
beginluacode
-- Utility function: Round number to nearest integer
function math.round ( x )
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
-- Typeset non-integer part of the number
function displaycents ( c , flag )
-- value of 'flag' can be either '1' or '0'
if flag==1 then
if c==0 then
tex.sprint ( " Only" )
elseif c==1 then
tex.sprint ( " and One Hundreth" )
else
tex.sprint ( " and \NumToName" .. c .. " Hundreths" )
end
elseif flag==0 then
if c==0 then
tex.sprint ( "Zero" )
elseif c==1 then
tex.sprint ( "One Hundreth" )
else
tex.sprint ( "\NumToName" .. c .. " Hundreths" )
end
end
end
-- 'num2name' is the main lua function
function num2name ( n )
local cents, lakhcrore, crore, lakh, rem
-- Retrieve decimal and integer parts of 'n'
cents = math.round ( 100 * ( n-math.floor(n) ) )
n = math.floor ( n ) -- integer part
-- calculate number of lakh crore, crore, lakh, and rem
lakhcrore = math.floor ( n / 1e12 ) -- lakh crore
crore = math.floor ( (n % 1e12) / 1e7 )-- crore
lakh = math.floor ( (n % 1e7) / 1e5 ) -- lakh
rem = n % 1e5 -- remainder
if n>0 then -- number >= 1.00
if lakhcrore>0 then
if crore==0 then
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh Crore" )
else
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh" )
end
if crore>0 or lakh>0 or rem>0 then tex.sprint (" ") end
end
if crore>0 then
tex.sprint ( "\NumToName" .. crore .. " Crore" )
if lakh>0 or rem>0 then tex.sprint (" ") end
end
if lakh>0 then
tex.sprint ( "\NumToName" .. lakh .. " Lakh" )
if rem>0 then tex.sprint (" ") end
end
if rem>0 then
tex.sprint ( "\NumToName" .. rem .. "" )
-- display fractional part ("cents")
displaycents ( cents , 1 )
end
else -- 0 <= number <= 0.99
displaycents ( cents , 0 )
end
end
endluacode
%% LaTeX wrapper macro:
newcommandnumtoword[1]directluanum2name(#1)
begindocument
noindent
begintabular@ll@
Verb:10^5: & numtoword10^5 \
Verb:2e7: & numtoword2e7 \
Verb:3e12: & numtoword3e12 \
Verb:6789e8: & numtoword6789e10 \
Verb:456e5: & numtoword456e5 \
Verb:123456:& numtoword123456 \
Verb:123456.78: & numtoword123450+6.78 \
Verb:1: & numtoword1 \
Verb:0: & numtoword0 \
Verb:0.01: & numtoword0.01 \
Verb:0.51: & numtoword0.51 \
endtabular
enddocument
(updated the answer to allow for fractional parts in the numbers as well as for very large numbers (>10^12))
Here's a LuaLaTeX-based solution that expresses numbers in words while using the so-called Indian numbering system. This system uses multiples of lakh (10^5
), crore (10^7
), and lakh crore (10^12
) instead of million, billion, and trillion to denote large numbers.
The code consists of 2 Lua utility functions, a Lua function called num2word
, and a LaTeX macro called numtoword
, which is just a front-end or "wrapper" for the num2word
function. The argument of numtoword
must be either a positive number or an expression that evaluates to a positive number under the usual rules of Lua syntax, e.g., 1+1+1
, 2e7
, and 3*10^5
. Commas are not allowed in the input of numtoword
. I.e., don't write num2word1,000,000
("Western" system) or numtoword10,00,000
("Indian" system), Instead, write num2word1000000
or num2word1e6
.
If the number contains a fractional part, the fractional part is rounded automatically to 2 digits. Most modern currencies I'm familiar contain a "cent" component, i.e., a fractional part that is a multiple of 0.01
.
If the number is smaller than 1 lakh (10^5) and if the number's fractional part equals 0, the suffix "Only" is appended to the word string; if the number's fractional part is nonzero, its word-equivalent (using "Hundredths") is appended. Finally, if the number is either exactly equal to 0 or is a large integer (>=1e5) which consists only of lakh, crore, and/or lakh crore (but no ten-thousands component), the "Only" suffix is not appended.
% !TEX TS-program = lualatex
documentclassarticle
usepackagegeometry % optional
usepackagefancyvrb % for "Verb" macro
usepackagenumname % for "NumToName" macro
% Modify some of the macros of the 'numname' package
renewcommand*namenumbercomma % default: ", "
renewcommand*tensunitsep % default: "-"
renewcommand*namenumberand % default: " and "
usepackageluacode % for "luacode" environment
beginluacode
-- Utility function: Round number to nearest integer
function math.round ( x )
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
-- Typeset non-integer part of the number
function displaycents ( c , flag )
-- value of 'flag' can be either '1' or '0'
if flag==1 then
if c==0 then
tex.sprint ( " Only" )
elseif c==1 then
tex.sprint ( " and One Hundreth" )
else
tex.sprint ( " and \NumToName" .. c .. " Hundreths" )
end
elseif flag==0 then
if c==0 then
tex.sprint ( "Zero" )
elseif c==1 then
tex.sprint ( "One Hundreth" )
else
tex.sprint ( "\NumToName" .. c .. " Hundreths" )
end
end
end
-- 'num2name' is the main lua function
function num2name ( n )
local cents, lakhcrore, crore, lakh, rem
-- Retrieve decimal and integer parts of 'n'
cents = math.round ( 100 * ( n-math.floor(n) ) )
n = math.floor ( n ) -- integer part
-- calculate number of lakh crore, crore, lakh, and rem
lakhcrore = math.floor ( n / 1e12 ) -- lakh crore
crore = math.floor ( (n % 1e12) / 1e7 )-- crore
lakh = math.floor ( (n % 1e7) / 1e5 ) -- lakh
rem = n % 1e5 -- remainder
if n>0 then -- number >= 1.00
if lakhcrore>0 then
if crore==0 then
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh Crore" )
else
tex.sprint ( "\NumToName" .. lakhcrore .. " Lakh" )
end
if crore>0 or lakh>0 or rem>0 then tex.sprint (" ") end
end
if crore>0 then
tex.sprint ( "\NumToName" .. crore .. " Crore" )
if lakh>0 or rem>0 then tex.sprint (" ") end
end
if lakh>0 then
tex.sprint ( "\NumToName" .. lakh .. " Lakh" )
if rem>0 then tex.sprint (" ") end
end
if rem>0 then
tex.sprint ( "\NumToName" .. rem .. "" )
-- display fractional part ("cents")
displaycents ( cents , 1 )
end
else -- 0 <= number <= 0.99
displaycents ( cents , 0 )
end
end
endluacode
%% LaTeX wrapper macro:
newcommandnumtoword[1]directluanum2name(#1)
begindocument
noindent
begintabular@ll@
Verb:10^5: & numtoword10^5 \
Verb:2e7: & numtoword2e7 \
Verb:3e12: & numtoword3e12 \
Verb:6789e8: & numtoword6789e10 \
Verb:456e5: & numtoword456e5 \
Verb:123456:& numtoword123456 \
Verb:123456.78: & numtoword123450+6.78 \
Verb:1: & numtoword1 \
Verb:0: & numtoword0 \
Verb:0.01: & numtoword0.01 \
Verb:0.51: & numtoword0.51 \
endtabular
enddocument
edited Sep 2 at 21:33
answered Sep 1 at 21:28


Mico
262k30354729
262k30354729
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f448845%2fconvert-numbers-to-words-e-g-111-one-hundred-eleven-using-the-indian-numb%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Welcome to TeX.SX! For me, your number sounds strange (I would think of it as
123,456.00
and "one hundred twenty-three thousand four hundred fifty-six [unit] zero [smaller unit]" to remove some edge cases). Could you please make a small example of what you have tried (MWE)?– TeXnician
Sep 1 at 13:51