Can we use Number
or is there something else type-specific? I used to go with Number
and it seems to be working for me. persent:Number = 1.01
…
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
We can use GLfloat
JavaScript (and by extension TypeScript) does not have specific types for integers and floats. There is only a
number
type. For really large numbers, we have BigInt.However, do note that the correct type to use for primitive values is all lowercase (
number
instead ofNumber
,string
instead ofString
etc.).Number
is a TypeScript type for the object that wraps around anumber
primitive which provides additional methods.Also, TypeScript can infer the type of a value when it is initialized. So
const myFloat = 1.01;
will be inferred as anumber
. If you can’t provide a value when the variable is declared, then you can provide the type annotation like this: