Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d74a3a0

Browse files
Merge pull request #27 from borsec-suveran/patch-24
Update 02_.md
2 parents 7bb19e9 + 0769918 commit d74a3a0

File tree

1 file changed

+1
-1
lines changed
  • 02_Data Types and Variables/00_Data Types/09_Parsing String to Number

1 file changed

+1
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
The sample code above has two different scenarios, one with a string only consisting of digits and the other with a string consisting of both digits and letters. The first two `parseInt()` and `parseFloat()` methods work normally and converts the whole string into an integer/float. `str_1` and `str_2` are a little more complicated as the string contains letters as well. In this case, the letters after the numbers are ignored. Therefore, "Hello" is ignored when the method is called and `console.log()` messages will print "123" and "12.3" respectively. This is the "strange" behavior exhibited by the `parseInt()` and `parseFloat()` method that you should be aware of when writing your own code.
1+
The sample code above has two different scenarios, one with a string only consisting of digits and the other with a string consisting of both digits and letters. The first two `parseInt()` and `parseFloat()` methods work normally and convert the whole string into an integer/float. `str_1` and `str_2` are a little more complicated as the string contains letters as well. In this case, the letters after the numbers are ignored. Therefore, "Hello" is ignored when the method is called and `console.log()` messages will print "123" and "12.3" respectively. This is the "strange" behavior exhibited by the `parseInt()` and `parseFloat()` method that you should be aware of when writing your own code.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /