/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Problem with javascript

I have this particular problem with javascript, maybe you can help me, because it’s a little bit weird:

[CODE]
<script type=”text/javascript”>
document.write(0.1 * 3);
document.write(0.1 * 7);
document.write(0.1 * 6);
</script>
[/CODE]

This executed in other IE or FF shows the following result:

[CODE]
0.30000000000000004
0.7000000000000001
0.6000000000000001
[/CODE]

any ideas.. or a solution?

Thanks in advance

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 02.2010 — document.write((0.1 * 3).<a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Number/ToFixed">toFixed</a>(2));
Problems_with_floating-point

floating point error
Copy linkTweet thisAlerts:
@cosmin86200authorMay 03.2010 — Thanks for your reply. It's not exactly the solution I wanted, but I managed to fix what I wanted.

Thanks again
×

Success!

Help @cosmin86200 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.19,
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,
)...