/    Sign up×
Community /Pin to ProfileBookmark

Multiplication Error or Bug

I noticed an error in one of my reports. I simplified the problem to the lines shown below. I have only tried this with IE6.0

document.getElementById(‘text1’).value = 0.4 * 33;

ANSWER
13.200000000000001

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mrhooNov 19.2007 — javascript uses floating point values for its numbers.

It varies according to the platform, but around 16 decimal places,

.9999999999999999 returns 1.

Set the precision of javascript math operations-

either use Math.floor(number*10000)/10000; (or 1000 or whatever) , or use number.toFixed(n) to 'chop' the return value to n decimal places.
×

Success!

Help @econnections 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.24,
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,
)...