JavaScript and client side scripting.
Moderator: General Moderators
-
vinoth
- Forum Contributor
- Posts: 113
- Joined: Thu Aug 02, 2007 3:08 am
- Location: India
-
Contact:
Post
by vinoth »
Is there any possible way to add two floating point values in javascript
because if we put + it will concordinate
So anybody know how to add two floating points
I need some suggestions, coding regarding this
Thanks in advance
-
VladSun
- DevNet Master
- Posts: 4313
- Joined: Wed Jun 27, 2007 9:44 am
- Location: Sofia, Bulgaria
Post
by VladSun »
???
Please, post your code...
There are 10 types of people in this world, those who understand binary and those who don't
-
superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign »
Have you looked at the
MDC? Very useful resource to keep handy when working with JavaScript objects.
-
vinoth
- Forum Contributor
- Posts: 113
- Joined: Thu Aug 02, 2007 3:08 am
- Location: India
-
Contact:
Post
by vinoth »
I didn't have any code in general I ask this.
Because the + operator is not used for adding in javascript.
-
superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign »
vinoth wrote:Because the + operator is not used for adding in javascript.
Since when?
-
vinoth
- Forum Contributor
- Posts: 113
- Joined: Thu Aug 02, 2007 3:08 am
- Location: India
-
Contact:
Post
by vinoth »
I solved the problem by using eval function for adding two float numbers
-
Begby
- Forum Regular
- Posts: 575
- Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby »
The problem is that the floats were actually strings, when you try to add strings it concatenates them.
right
7.4 + 7.5 = 14.9
wrong
'7.4' + '7.5' = '7.47.5'
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
I'd avoid the eval by using the constructors or parseFloat methods instead.