skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    We can use GLfloat

    interface Persentage{
    persent:GLfloat;
    }
    const persent:Persentage = {persent:1.01};
    console.log(persent)
    

  2. 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 of Number, string instead of String etc.). Number is a TypeScript type for the object that wraps around a number 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 a number. If you can’t provide a value when the variable is declared, then you can provide the type annotation like this:

    let myFloat: number;
    
    // Somewhere later
    myFloat = 1.01;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search