When I try to parseInt() it says:
_this2.state.grade.parseInt is not a function
Code:
this.state = {grade: "1"}
let grade = this.state.grade.parseInt()
Does this function not work in React Native? If so how can I convert it to int?
Try:
Number.parseInt(this.state.grade, 10)
// the 2nd argument is the base mathematical
// system to use for parsing and should
// always be passed to avoid confusion and
// ensure predictable behaviour
parseInt is a global function as part of ECMAScript 2015 wich might not be vailable.
Alternatively use:
Number.parseInt(value, base)
base is important because it result into different values :
Octadecimal
Number.parseInt( '011', 8)
-> 9
Decimal
Number.parseInt( '011', 10)
->11
Hexa Decimal
Number.parseInt( '011', 16)
->17
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With