/    Sign up×
Community /Pin to ProfileBookmark

Multiply dollar amounts and keep the zeros

Hi all,

I am trying to do something really simple. I have a product page that multiplies a users quantity input by the price I assign. It works great, but it leaves out the zeros. For example: 1.50 multiplied by 10 displays as 15 instead of 15.00.

Am I going to have to write a bunch of logical statements to fix that or is there an easier way?

I appreaciate any help in advance,
Thank You.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 09.2004 — [font=monospace]<script type="text/javascript">

<!--

alert(Number(1.50 * 10).toFixed(2))

// -->

</script>[/font]
Copy linkTweet thisAlerts:
@ai3rulesauthorAug 09.2004 — Hi, thanks for your quick reply. That method isnt working for me, most probably because I am using variables and arrays in the equation.

This is the line I am using:

document.write(pricing[i]*info[0])



where pricing[i] = "1.50" and info[0] is a string split from the location.search(the quantity entered by the user in the previous page).



How can I implement the Number and toFixed(2) method there?



Thanks
Copy linkTweet thisAlerts:
@steelersfan88Aug 09.2004 — [i]Originally posted by Charles [/i]

[B][font=monospace]<script type="text/javascript">

<!--

document.write(Number(1.50 * 10).toFixed(2))

// -->

</script>[/font] [/B]
[/QUOTE]
Then just replace the 1.50 and the 10, as Charles mentioned. (Please don't yell at me for modifying your code)
Copy linkTweet thisAlerts:
@ai3rulesauthorAug 09.2004 — Thanks, that didnt work for me before for some reason - must have wrote it wrong.
Copy linkTweet thisAlerts:
@CharlesAug 09.2004 — What [i]exactly[/i] isn't working for you? It would be best if you posted the URL for the page in question. But be aware,really old browsers don't support "Number.toFixed()".
Copy linkTweet thisAlerts:
@ai3rulesauthorAug 10.2004 — Sorry about that, I didnt mean you wrote it wrong - I must have wrote the code wrong the first time. It is working for me now though, Thanks.
×

Success!

Help @ai3rules spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...