Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parseMoney()

Status
Not open for further replies.

tnsbuff

Technical User
Jan 23, 2002
216
US
Hi,

I'm fairly new to JavaScript and I'm trying to use the parseMoney() or parseDec() methods to achieve 2 decimal places on my calculations. Both give me an "object required" error, although everything calculates and displays fine if I don't use these methods. Here's the code I've tried:

document.form_name.field_name.value = parseMoney(calculated_total);

document.form_name.field_name.value = parseDec(calculated_total, 2);

Can anyone tell me what I'm doing wrong?

Thanks very much!
 
No, not Java functions; taken directly from the second link (you provided the same one). It doesn't work for me though for some reason.
 
what browser are you using?

what type of variable is calculated_total, string, int, ... ?

how have you referenced the js files, can we see a bit more code with the js file reference and the script block where you make the call to parseDec
 
Hi sjravee,

Thanks for responding again to my question.

I'm using IE6.0. Actually, calculated_total is not the actual variable name that I used. The actual variables are F_Total, P_Total, Shipping_Total and Grand_Total. You can see the full code here:


(I'm sure there's a more elegant way to code what I'm doing but I'm new and it works, except for the fact that I can't seem to force 2 decimal places for my currency totals.)

I converted all entries using parseFloat() before totaling the numbers. Should I have done it differently?

Thanks very much!
 
Just wanted to mention also that I removed the parseMoney(Grand_Total) code because it kept causing the "object required" error.
 
Never mind. I thought parseMoney() and parseDec() were built-in functions similar to formatNumber() in asp. I guess they're not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top