Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare and deal with float type in typescript?

Tags:

I have angular App which interact with backend required to send json like this:

{"prop": 654646f} 

I have two problems, I can't find the type float in typescript also if the value have quoted in default JSON it isn't accepted. So how to remove quotes from certain property value in JSON?

like image 522
Tamer Hussien Avatar asked May 07 '18 09:05

Tamer Hussien


People also ask

Is there a float type in TypeScript?

There is no float type in Typescript. All numbers are from the type number .

Does TypeScript number include float?

Number. As in JavaScript, all numbers in TypeScript are either floating point values or BigIntegers. These floating point numbers get the type number , while BigIntegers get the type bigint .

How do I declare in TypeScript?

The type syntax for declaring a variable in TypeScript is to include a colon (:) after the variable name, followed by its type. Just as in JavaScript, we use the var keyword to declare a variable. Declare its type and value in one statement.


1 Answers

There is no float type in Typescript. All numbers are from the type number.

If you want to cast an string as number you can simply do it with the + operator. Example:

myNumberString: string = "25"; myNumber: number = +myNumberString; 
like image 87
ochs.tobi Avatar answered Oct 16 '22 08:10

ochs.tobi