• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Digit to Words

 
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
I need to convert numbers to words . E.g :- 1445
one thousand Four Hundred and Forty Five.
Is there a class provided in the API .. well i couldn't find one. Can anybody guide me how should i go about developing such a class if there isn't any ?
Thanks in advance
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no built-in API that will do this for you, so you'll have to write your own.
One idea is to use the mod (%) operator to help figure out what value you have... something like this
---------------
1445
1445 %1000 = 1, so you know you have one thousand
(1445 - 1000) % 100 = 4, so you know you have four hundred
(445 - 400) % 10 = 4, so you know you have forty
(45 - 40) % 1 = 5, so you know you have five
which gives you something close to one thousand Four Hundred and Forty Five.
you'll just have to make a big mapping between what place you're in (thousands, hundreds, tens, ones, etc) and what the written value is for each number 0-9 in that value (thirty, forty, fifty, etc.
---------------
I'm moving this to Java In General (Intermediate) as I don't think this is an advanced question.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic