The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Sorry for not getting back and yes I tried all the scripts, there was a small problem with your script in that if you entered:alert(MoneyConverter.toTextDollars(1.01, "en")); it would return 1 dollars and 1 cents and not the singular dollar and cent,
and it is easer (for me) to have separate scripts for each language.

I've come across this script which looks like it could be changed but it has no fractions (cents) and no dollar or dollars but it looks easy to add any excepts to it.

I've had a quick read, and will go back later and go though it again when I've a bit more time, the Javascript is over my head, but I sort of understand a bit of what he is doing,

I've been pressing on with your script and sorted a fair bit but having problems sorting out a couple of things,

in French 71 to 79 is the equivalent of saying 60+11 (71), 60+12 (72), 60+13 (73) etc, ( don't blame me I didn't make it up )
anyway having a few problems getting this to work, I'll try a bit longer if I have too much trouble I come back here.

I took a quick poke at revamping my original script to function more like what you'd like. The changes include:

1. I created an i18n 'object' to handle the text translations (internationalization) and handling singular vs. plural strings (based very much on that article I linked to above but with some minor changes to minimize the litter in the global namespace). I *think* all of my translations are correct, but you should probably verify them.

2. I created separate global objects (enMoneyConverter and frMoneyConverter) for each language. You could put each of these in their own file if you like.

3. I was able to reduce the methods down to a single public method (toTextDollars), and make the helper methods private (this is just good OO design). The private methods (toTextualValue) contain the bulk of the language dependent logic.

I'm not sure if the French logic is 100&#37; correct. My French is a bit rusty. But this might get you going in the right direction. The logic for each language would be self contained so you could easily add new languages without having to modify the existing language code.

Looks very promising, I've had a little play and took a look at the script,
its great just what I ordered, just for my workings, I would normally have separate scripts, but now I'm all thinking loads of different things,

I will go though and customize it, not that it will help you but this is what I did with your old script (bearing in mind I'm a virgin javascriptor) with a little bit of HTML coding, you might find it useful

Now sit down and pour yourself a nice long beer, put your feet up and have a laugh at my attempt that should cheer you up

if (printnumber > 99) {
But you then only peel off 3 characters... what if the number is 1000?
Instead, consider dividing the number by multiples of 10 to strip off each digit (in my example, this was the part that started with var millions = Math.floor(amt / 1000000).

if (firstnumber == 9)
Now you're comparing a string (firstnumber) with an integer. Another reason to use the Math.floor approach instead. Also, instead of a bunch of if/else if statements, a switch would be more apporopriate (if you decide to go this route).

if (printnumber == 200){strTemp = "deux cents " ;}
But what if printnumber is 201 - 299? It's still going to start with deux cents, but you're not accounting for that. Likewise for 300, 400, 500, 600, 700, 800, and 900.

if (middlenumber == 9) {
Same comment as with firstnumber. But also, 91 is not supposed to be 'quatre-vingt-dix-un'. It's supposed to be 'quatre-vingt-onze' (80 + 11). So I think your logic is incorrect here.

-- that was as far as I got... have something else I need to work on. Your actual code looks fine, but I think the logic is not quite right. Take a closer look at what I was doing. I did find a small bug in my French code which I've fixed in this code below. I also added a bunch of comments so you can better understand what the code is doing (and why). Hope this helps.

I've had another play with the script, it far the best script, thanks a lot,
I found the "etzero" problem, but I've change that to display "00" if no cents are entered, and Francs to euros, (you haven't be here for a while )
and dollars to pounds, pence, penny, and just getting the feel of it,

the last script is great, I need all the help I can and the comments you put in help a lot, I'll just slim down the final copy and remove most of them,

I understand what your saying I hold my hands up with the maths part, Its way beyond me, so I was trying to work around it, but it involved ten times more code, with spending a bit of time with this script I might get a bit better at understanding it all,
I hope you don't mind me keep bugging you too much, I wouldn't want to over stretch your kind help.

I'm Back

Hi Guys
I've been busy knocking up my new website with the new script but now need to add two new languages, German which is very much the same as English rules except 20 > 99 are reversed (twenty six = six & twenty).

the other one is Spanish which is a little harder to do if I start with the German language 1st it might help me get a grasp of how to do the Spanish one.

German.

as explained I have to reverse all the numbers between the 20 and 99.
so 26 = six and twenty, 126 = hundred six and twenty,

I've tried swapping bits about to try and revers them but just keep getting rubbish back (numbers or blank )
so can anyone tell me where I should start.