/    Sign up×
Community /Pin to ProfileBookmark

How to show ONLY Two Decimal Points

I have a field I’m updating with the following code

parent.Frame1.RT.answer.value = Number(myform.Total1.value) + Number(myform.Total2.value)

The problem is the answer is 65.85744

I need to show the answer as 65.85

How can I do this?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliDec 30.2003 — use JavaScript function Number.toFoxed(int decimal points allowed)

e.g

parent.Frame1.RT.answer.value = (Number(myform.Total1.value) + Number(myform.Total2.value)).toFixed(2)
Copy linkTweet thisAlerts:
@rwaringauthorDec 30.2003 — awesome! I didn't know that existed. Is there a place I can see all the Javascript built in stuff like that .tofixed(x) ???
Copy linkTweet thisAlerts:
@PittimannDec 30.2003 — Hi!

parent.Frame1.RT.answer.value = (Number(myform.Total1.value) + Number(myform.Total2.value)).toFixed(2);

Cheers - Pit

[B]Edit: Sorry for posting that - Khalid was too fast[/B]
Copy linkTweet thisAlerts:
@PittimannDec 30.2003 — Hi!

Hope, this will at least be of some help:

http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/number.html#1207032

On top of the page you can go to Contents & Index for other stuff...

Cheers - Pit
×

Success!

Help @rwaring 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.15,
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,
)...