Saved Bookmarks
| 1. |
Solve : Help pls..Numbers into words? |
|
Answer» Hello I want to change it in to a java code instead so it can work on internet explorer page. Also, post the code you have at the moment.Ok Well I'm new to coding so I guess javascript My Programming Code Is...... /* * Function: number_to_words * Description: recursive numerics to words function * Converts a given integer (in range [0..1T-1], inclusive) into * alphabetical format ("one", "two", etc.) * int * return string */ function number_to_words($number) { if (($number < 0) || ($number > 999999999)) { throw new Exception("Number is out of range"); } $Gn = floor($number / 1000000); /* Millions (giga) */ $number -= $Gn * 1000000; $kn = floor($number / 1000); /* Thousands (kilo) */ $number -= $kn * 1000; $Hn = floor($number / 100); /* Hundreds (hecto) */ $number -= $Hn * 100; $Dn = floor($number / 10); /* Tens (deca) */ $n = $number % 10; /* ONES */ $result = ""; if ($Gn) { $result .= number_to_words($Gn) . " Million"; } if ($kn) { $result .= (empty($result) ? "" : " ") . number_to_words($kn) . " Thousand"; } if ($Hn) { $result .= (empty($result) ? "" : " ") . number_to_words($Hn) . " Hundred"; } $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "THIRTEEN", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", "Nineteen"); $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eigthy", "Ninety"); if ($Dn || $n) { if (!empty($result)) { $result .= " and "; } if ($Dn < 2) { $result .= $ones[$Dn * 10 + $n]; } ELSE { $result .= $tens[$Dn]; if ($n) { $result .= "-" . $ones[$n]; } } } if (empty($result)) { $result = "zero"; } return $result; } That's PHP. All you do is called the number_to_words function, i.e. Code: [Select]<?php number_to_words(560); ?>...should return "five hundred and sixty".yea but What I mean Is, I've opened up text Document and TYPED in the html,head,script,body & html the Basic stuff and I've placed it in between the Placed it here and when I open It it doesn't do anything just shows me the code. I don't know anything about php. Quote I've opened up text Document and typed in the html,head,script,body & html the Basic stuff and I've placed it in between the <script>Placed it here</script> and when I open It it doesn't do anything just shows me the code.That's the problem. Here: http://javascript.about.com/library/bltoword.htm More: Goooooogleyea I was hoping to change 1-24 into words that I type in ie:- 1 = pasta 2 = chips 3 = pie 4 = soup 5 = shreddies etc etc Say I type 24 words and it changes all my numbers into those words To be honest, all the hard work has been done for you. Converting the code from PHP to javascript is not that difficult. Do you want someone to do the whole exercise for you? You might be interested in trying http://www.vworker.com/ - there are coders in India that would do something like this for $5 or so. |
|