/    Sign up×
Community /Pin to ProfileBookmark

Hi,

How do you round this number 23.8923451 to get 23.89?
Math.round is not good. It gives 24

Thx
Joe

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JPnycMar 24.2006 — Just use toFixed(2);
Copy linkTweet thisAlerts:
@joecool2005authorMar 24.2006 — can you give me a example?

Thx
Copy linkTweet thisAlerts:
@TheBearMayMar 24.2006 — <i>
</i>var num = 23.8923451;
alert(num.toFixed(2));
Copy linkTweet thisAlerts:
@JuuitchanMar 24.2006 — The toFixed method returns a [b]string[/b]. (If you unintentionally "add" a number to a string, you will probably get an unpleasant surprise!)
Copy linkTweet thisAlerts:
@netbuddyMar 24.2006 — result = Math.round(value*100)/100;
×

Success!

Help @joecool2005 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...