Click here to Skip to main content
16,013,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My current output:
TWO LACS ONE THOUSAND EIGHT HUNDRED SIX ONLY/-

I want following output:
TWO LACS ONE THOUSAND EIGHT HUNDRED AND SIX ONLY/-

My formula for currency conversion of numbers to words is:

C#
numbervar RmVal:=0; 
numbervar Amt:=0; 
numbervar pAmt:=0; 
stringvar InWords :=""; 
Amt := ({DtBHeader.GrandTotal}); 
if Amt > 10000000 then RmVal := truncate(Amt/10000000); 
if Amt = 10000000 then RmVal := 1; 
if RmVal = 1 then 
InWords := InWords + " " + towords(RmVal,0) + " crore" 
else 
if RmVal > 1 then InWords := InWords + " " + towords(RmVal,0) + " crores";

Amt := Amt - Rmval * 10000000; 
if Amt > 100000 then RmVal := truncate(Amt/100000); 
if Amt = 100000 then RmVal := 1; 
if RmVal >=1 then 
InWords := InWords + " " + towords(RmVal,0) + " lacs";

Amt := Amt - Rmval * 100000; 
if Amt > 0 then InWords := InWords + " " + towords(truncate(Amt),0); 
pAmt := (Amt - truncate(Amt)) * 100; 
if pAmt > 0 then 
InWords := InWords + " and " + towords(pAmt,0) + " paisa only/-" 
else 
InWords :=  InWords  + " only/-"; 
UPPERCASE(InWords)
Posted
Updated 27-Dec-14 4:46am
v2
Comments
BillWoodruff 27-Dec-14 2:42am    
Is it the case if the value to be converted is 201,800 Rp. that the output you would want is: TWO LACS AND ONE THOUSAND EIGHT HUNDRED ONLY ?

The answer seems obvious: you need perform the tests for possible final "states" in advance.

1 solution

Got the correct answer:

C#
numbervar RmVal:=0; 
numbervar Amt:=0; 
numbervar pAmt:=0; 
stringvar Inwards :=" ";
numbervar totalAmt;
totalAmt := Sum ({DtBHeader.GrandTotal});
Amt := totalAmt;

if Amt >= 10000000 then
    RmVal := truncate(Amt/10000000); 
if RmVal = 1 then 
    Inwards := Inwards + " " + towords(RmVal,0) + " crore" 
else 
    if RmVal > 1 then 
        Inwards := Inwards + "  " + towords(RmVal,0) + " crores";
Amt := Amt - Rmval * 10000000;

RmVal := 0;
if Amt >= 100000 then 
    RmVal := truncate(Amt/100000); 
if RmVal = 1 then 
    Inwards := Inwards + "  " + towords(RmVal,0) + " lakh"
Else
    If RmVal > 1 then 
        Inwards := Inwards + "  " + ToWords(RmVal,0) + " lakhs";
Amt := Amt - Rmval * 100000;

RmVal := 0;
if Amt >= 1000 then 
    RmVal := truncate(Amt/1000);
if RmVal =1 then 
    Inwards := Inwards + "  " + towords(RmVal,0) + " thousand"
Else
    if RmVal > 1 then 
        Inwards := Inwards + "  " + towords(RmVal,0) + " thousand ";
Amt := Amt - RmVal * 1000;

RmVal := 0;
if Amt >= 100 then 
    RmVal := truncate(Amt/100);
if RmVal =1 then 
    Inwards := Inwards + " " + towords(RmVal,0) + " hundred and"
Else
    if RmVal > 1 then 
        Inwards := Inwards + " " + towords(RmVal,0) + " hundred and";
Amt := Amt - RmVal * 100;

        
if Amt > 0 then 
    Inwards := Inwards + " " + towords(truncate(Amt),0);

pAmt := (Amt - truncate(Amt)) * 10;

if pAmt > 0 then 
    Inwards := Inwards + " and " + towords(pAmt,0) + " paisa only /-" 
else 
    Inwards := Inwards + " only /-";

UPPERCASE(Inwards) 


OUTPUT: NINETEEN THOUSAND FOUR HUNDRED AND SEVENTY-SEVEN ONLY /-
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900