Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Bounty
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Convert Rupees (Numbers) to Words (String) using C#.NET
WhatsApp
Pintoo Yadav
May 06
2015
55.4
k
0
4
public
string
ConvertNumbertoWords(
long
number)
{
if
(number == 0)
return
"ZERO"
;
if
(number < 0)
return
"minus "
+ ConvertNumbertoWords(Math.Abs(number));
string
words =
""
;
if
((number / 1000000) > 0)
{
words += ConvertNumbertoWords(number / 100000) +
" LAKES "
;
number %= 1000000;
}
if
((number / 1000) > 0)
{
words += ConvertNumbertoWords(number / 1000) +
" THOUSAND "
;
number %= 1000;
}
if
((number / 100) > 0)
{
words += ConvertNumbertoWords(number / 100) +
" HUNDRED "
;
number %= 100;
}
//if ((number / 10) > 0)
//{
// words += ConvertNumbertoWords(number / 10) + " RUPEES ";
// number %= 10;
//}
if
(number > 0)
{
if
(words !=
""
) words +=
"AND "
;
var unitsMap =
new
[]
{
"ZERO"
,
"ONE"
,
"TWO"
,
"THREE"
,
"FOUR"
,
"FIVE"
,
"SIX"
,
"SEVEN"
,
"EIGHT"
,
"NINE"
,
"TEN"
,
"ELEVEN"
,
"TWELVE"
,
"THIRTEEN"
,
"FOURTEEN"
,
"FIFTEEN"
,
"SIXTEEN"
,
"SEVENTEEN"
,
"EIGHTEEN"
,
"NINETEEN"
};
var tensMap =
new
[]
{
"ZERO"
,
"TEN"
,
"TWENTY"
,
"THIRTY"
,
"FORTY"
,
"FIFTY"
,
"SIXTY"
,
"SEVENTY"
,
"EIGHTY"
,
"NINETY"
};
if
(number < 20) words += unitsMap[number];
else
{
words += tensMap[number / 10];
if
((number % 10) > 0) words +=
" "
+ unitsMap[number % 10];
}
}
return
words;
}
Convert Number to String
Convert to String
Up Next
Convert Rupees (Numbers) to Words (String) using C#.NET