9 Replies - 5428 Views - Last Post: 05 September 2009 - 08:26 PM Rate Topic: -----

#1 scias23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-July 09

convert number to words..

Post icon  Posted 05 September 2009 - 10:13 AM

i'm stuck in figuring out the right formula to use in this problem...

i came up with this.
private static int number, h, o, t;

		h = number/100;
		t = (number-(h*100))/10;
		o = ((number-(h*100))-(t*10));



but this can only convert numbers up to 999. what i want to do is to convert numbers up to 9999.

what is the formula for the thousands place? are my formulas correct?

waaah T.T

Is This A Good Question/Topic? 0
  • +

Replies To: convert number to words..

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: convert number to words..

Posted 05 September 2009 - 10:21 AM

i dont quite understand what are you trying to do?
Was This Post Helpful? 0
  • +
  • -

#3 scias23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-July 09

Re: convert number to words..

Posted 05 September 2009 - 10:23 AM

View Postmostyfriedman, on 5 Sep, 2009 - 09:21 AM, said:

i dont quite understand what are you trying to do?


i want to convert numbers into words.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,085
  • Joined: 18-April 07

Re: convert number to words..

Posted 05 September 2009 - 10:29 AM

Look for a pattern...

1) 998 / 10? 99 and 998 % 10 = 8
2) 99 / 10? 9 and 99 % 10 = 9
3) 9 is left over


For the number 1288

1) 1288 / 10? 128 and 1288 % 10 = 8
2) 128 / 10? 12 and 128 % 10 = 8
3) 12 / 10? 1 and 12 % 10 = 2
4) 1 is left over

Now think of a loop for this. Perhaps knowing when to end when number < 10. At each step then you can use a switch statement to convert the appropriate number to a word

:)

This post has been edited by Martyr2: 05 September 2009 - 10:30 AM

Was This Post Helpful? 1

#5 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: convert number to words..

Posted 05 September 2009 - 10:42 AM

alright well you can have arrays of strings, one with the tens, and another with the hundreds etc..to convert a number to its corresponding string you will have to play around with division and moduli..for example if you have 999 then you can array[999/100] which will contain "nine hundred" and to get the rest of the number you can array2[999%100] which may contain ninety nine..it all depends on how you arrange your arrays..i of course wont do it like that but i will use the same logic..hope this helps a lil
Was This Post Helpful? 0
  • +
  • -

#6 scias23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-July 09

Re: convert number to words..

Posted 05 September 2009 - 07:09 PM

what if i want to convert 9999 into words?

View Postmostyfriedman, on 5 Sep, 2009 - 09:42 AM, said:

alright well you can have arrays of strings, one with the tens, and another with the hundreds etc..to convert a number to its corresponding string you will have to play around with division and moduli..for example if you have 999 then you can array[999/100] which will contain "nine hundred" and to get the rest of the number you can array2[999%100] which may contain ninety nine..it all depends on how you arrange your arrays..i of course wont do it like that but i will use the same logic..hope this helps a lil

Was This Post Helpful? 0
  • +
  • -

#7 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: convert number to words..

Posted 05 September 2009 - 07:14 PM

just use a similar approach
Was This Post Helpful? 0
  • +
  • -

#8 scias23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-July 09

Re: convert number to words..

Posted 05 September 2009 - 07:29 PM

omg i don't get it. :(

View PostMartyr2, on 5 Sep, 2009 - 09:29 AM, said:

Look for a pattern...

1) 998 / 10? 99 and 998 % 10 = 8
2) 99 / 10? 9 and 99 % 10 = 9
3) 9 is left over


For the number 1288

1) 1288 / 10? 128 and 1288 % 10 = 8
2) 128 / 10? 12 and 128 % 10 = 8
3) 12 / 10? 1 and 12 % 10 = 2
4) 1 is left over

Now think of a loop for this. Perhaps knowing when to end when number < 10. At each step then you can use a switch statement to convert the appropriate number to a word

:)

Was This Post Helpful? 0
  • +
  • -

#9 scias23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-July 09

Re: convert number to words..

Posted 05 September 2009 - 08:16 PM

could you please give me a hint of the loop here?

View PostMartyr2, on 5 Sep, 2009 - 09:29 AM, said:

Look for a pattern...

1) 998 / 10? 99 and 998 % 10 = 8
2) 99 / 10? 9 and 99 % 10 = 9
3) 9 is left over


For the number 1288

1) 1288 / 10? 128 and 1288 % 10 = 8
2) 128 / 10? 12 and 128 % 10 = 8
3) 12 / 10? 1 and 12 % 10 = 2
4) 1 is left over

Now think of a loop for this. Perhaps knowing when to end when number < 10. At each step then you can use a switch statement to convert the appropriate number to a word

:)

Was This Post Helpful? 0
  • +
  • -

#10 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: convert number to words..

Posted 05 September 2009 - 08:26 PM

Think o what number the division or moduli gives you when you compare it to the full number.
EX)
integer division:

9999/10 = 999 nine thousand
999/10 = 99 nine hundred
99/10 = 9 and ninety
9/10 = 0

it took 3 times to simplify the number to the ones place so you know it is 9 thousand

9999%10 = 9 nine
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1