|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can we write numbers?
When a user write numbers into text box, lets say any number from 0 to 99999 or more, can we show it on the page as we read/spell?
if he writes 456 it should show four hundred and fifty six etc. |
|
#2
|
|||
|
|||
|
RE: Can we write numbers?
Yes you can parse the number into individual digits and use an array to store the text for each. Note that handling the teens (11-19) requires some special handling at every level.
B |
|
#3
|
|||||
|
|||||
|
RE: Can we write numbers?
I got to thinking about this and here is the code. It takes a variable $input and spits it out as words. Could definately be refined (it won't handle a number with comma's yet but you could strip comma's), I also think it will choke on a number that has millions but with a zero value in the thousands, but you just need to add a little exception handling.
php Code:
B |
|
#4
|
|||
|
|||
|
RE: Can we write numbers?
Thanks bakertrg,
it works! how can we add "and" conjuctions. because while we read we sometimes use "and". |
|
#5
|
||||
|
||||
|
RE: Can we write numbers?
Where do you want to add them? You can easily add them after the word hundred at the bottom of the script or the words thousand etc. in the switch statement at the top. Be sure to add a space at the end of any text string you add.
B |
|
#6
|
||||
|
||||
|
RE: Can we write numbers?
one other thing, you can easily make this work for bigger numbers if you add new cases to the switch statement. The code is basically checking how many blocks of three digits you have and apending the case text as appropriate.
B |
|
#7
|
|||
|
|||
|
RE: Can we write numbers?
normally we read as
125 =one hundred and twenty five or 105 =one hundred and five or 1001 =one thousand and one 15972=fiteen thousand nine hundred and sevent two |
|
#8
|
|||
|
|||
|
RE: Can we write numbers?
I have added and after hundred. it spits out 125 ok but when I write 100 it says one "hundred and"
|
|
#9
|
||||
|
||||
|
RE: Can we write numbers?
add an if statement that checks to see if following the hundred the next two characters are not 00.
if (substr($number, 0, 2) == '00'){ $output .= 'hundred '; } else { $output .= 'hundred and '; } |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Can we write numbers? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|