Javascript parseFloat() change number [closed]
I have a strange problem with JavaScript
.
I have text value in a textbox
'25000000' when i am
using parsefloat(txt.value)
, the returned value is 25000 !??
Why is 25000000 changed to 25000 ?
javascript asp.net
closed as off-topic by James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub Nov 26 '18 at 22:48
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have a strange problem with JavaScript
.
I have text value in a textbox
'25000000' when i am
using parsefloat(txt.value)
, the returned value is 25000 !??
Why is 25000000 changed to 25000 ?
javascript asp.net
closed as off-topic by James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub Nov 26 '18 at 22:48
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub
If this question can be reworded to fit the rules in the help center, please edit the question.
1
Is it definitely all zeros? If there was an O hidden in there instead for instance, theparseFloat
would stop at that point and return just what had been parsed so far. Other than that, there's not really enough information in your question to give you an answer.
– James Thorpe
Nov 26 '18 at 9:13
txt.value from input?
– Mars.Tsai
Nov 26 '18 at 9:14
1
Can you provide a minimal, complete and verifiable example that demonstrates the problem?
– James
Nov 26 '18 at 9:22
add a comment |
I have a strange problem with JavaScript
.
I have text value in a textbox
'25000000' when i am
using parsefloat(txt.value)
, the returned value is 25000 !??
Why is 25000000 changed to 25000 ?
javascript asp.net
I have a strange problem with JavaScript
.
I have text value in a textbox
'25000000' when i am
using parsefloat(txt.value)
, the returned value is 25000 !??
Why is 25000000 changed to 25000 ?
javascript asp.net
javascript asp.net
edited Nov 26 '18 at 10:00
JustLearning
1,24421637
1,24421637
asked Nov 26 '18 at 9:10
Ali RadAli Rad
243
243
closed as off-topic by James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub Nov 26 '18 at 22:48
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub Nov 26 '18 at 22:48
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – James Thorpe, Tetsuya Yamamoto, Madhur Bhaiya, sideshowbarker, Paul Roub
If this question can be reworded to fit the rules in the help center, please edit the question.
1
Is it definitely all zeros? If there was an O hidden in there instead for instance, theparseFloat
would stop at that point and return just what had been parsed so far. Other than that, there's not really enough information in your question to give you an answer.
– James Thorpe
Nov 26 '18 at 9:13
txt.value from input?
– Mars.Tsai
Nov 26 '18 at 9:14
1
Can you provide a minimal, complete and verifiable example that demonstrates the problem?
– James
Nov 26 '18 at 9:22
add a comment |
1
Is it definitely all zeros? If there was an O hidden in there instead for instance, theparseFloat
would stop at that point and return just what had been parsed so far. Other than that, there's not really enough information in your question to give you an answer.
– James Thorpe
Nov 26 '18 at 9:13
txt.value from input?
– Mars.Tsai
Nov 26 '18 at 9:14
1
Can you provide a minimal, complete and verifiable example that demonstrates the problem?
– James
Nov 26 '18 at 9:22
1
1
Is it definitely all zeros? If there was an O hidden in there instead for instance, the
parseFloat
would stop at that point and return just what had been parsed so far. Other than that, there's not really enough information in your question to give you an answer.– James Thorpe
Nov 26 '18 at 9:13
Is it definitely all zeros? If there was an O hidden in there instead for instance, the
parseFloat
would stop at that point and return just what had been parsed so far. Other than that, there's not really enough information in your question to give you an answer.– James Thorpe
Nov 26 '18 at 9:13
txt.value from input?
– Mars.Tsai
Nov 26 '18 at 9:14
txt.value from input?
– Mars.Tsai
Nov 26 '18 at 9:14
1
1
Can you provide a minimal, complete and verifiable example that demonstrates the problem?
– James
Nov 26 '18 at 9:22
Can you provide a minimal, complete and verifiable example that demonstrates the problem?
– James
Nov 26 '18 at 9:22
add a comment |
2 Answers
2
active
oldest
votes
I think there is an alphabet somewhere in your numbers. Check the example below.There is an error in your code.
parseFloat(" 250000000 ") = 250000000
parseFloat("2018@geeksforgeeks") = 2018
parseFloat("geeksforgeeks@2018") = NaN
add a comment |
Thanks for all Responses.
The problem was for ',' in price.
Of course we replace ',' with '' ,but replace method
only change first one like "25,000,000,000"=>"25000,000,000".
I used str.split(',').join('')
and problem solve and parsefloat returned correctly.
regards
ali
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think there is an alphabet somewhere in your numbers. Check the example below.There is an error in your code.
parseFloat(" 250000000 ") = 250000000
parseFloat("2018@geeksforgeeks") = 2018
parseFloat("geeksforgeeks@2018") = NaN
add a comment |
I think there is an alphabet somewhere in your numbers. Check the example below.There is an error in your code.
parseFloat(" 250000000 ") = 250000000
parseFloat("2018@geeksforgeeks") = 2018
parseFloat("geeksforgeeks@2018") = NaN
add a comment |
I think there is an alphabet somewhere in your numbers. Check the example below.There is an error in your code.
parseFloat(" 250000000 ") = 250000000
parseFloat("2018@geeksforgeeks") = 2018
parseFloat("geeksforgeeks@2018") = NaN
I think there is an alphabet somewhere in your numbers. Check the example below.There is an error in your code.
parseFloat(" 250000000 ") = 250000000
parseFloat("2018@geeksforgeeks") = 2018
parseFloat("geeksforgeeks@2018") = NaN
answered Nov 26 '18 at 9:16
lutakynlutakyn
7211
7211
add a comment |
add a comment |
Thanks for all Responses.
The problem was for ',' in price.
Of course we replace ',' with '' ,but replace method
only change first one like "25,000,000,000"=>"25000,000,000".
I used str.split(',').join('')
and problem solve and parsefloat returned correctly.
regards
ali
add a comment |
Thanks for all Responses.
The problem was for ',' in price.
Of course we replace ',' with '' ,but replace method
only change first one like "25,000,000,000"=>"25000,000,000".
I used str.split(',').join('')
and problem solve and parsefloat returned correctly.
regards
ali
add a comment |
Thanks for all Responses.
The problem was for ',' in price.
Of course we replace ',' with '' ,but replace method
only change first one like "25,000,000,000"=>"25000,000,000".
I used str.split(',').join('')
and problem solve and parsefloat returned correctly.
regards
ali
Thanks for all Responses.
The problem was for ',' in price.
Of course we replace ',' with '' ,but replace method
only change first one like "25,000,000,000"=>"25000,000,000".
I used str.split(',').join('')
and problem solve and parsefloat returned correctly.
regards
ali
answered Nov 26 '18 at 11:17
Ali RadAli Rad
243
243
add a comment |
add a comment |
1
Is it definitely all zeros? If there was an O hidden in there instead for instance, the
parseFloat
would stop at that point and return just what had been parsed so far. Other than that, there's not really enough information in your question to give you an answer.– James Thorpe
Nov 26 '18 at 9:13
txt.value from input?
– Mars.Tsai
Nov 26 '18 at 9:14
1
Can you provide a minimal, complete and verifiable example that demonstrates the problem?
– James
Nov 26 '18 at 9:22