Recently, I was building a financial dashboard application where I needed to convert string inputs to double values for calculations.
The challenge with TypeScript is that it doesn’t have a specific “double” type like some other languages. Instead, we use the number type, which can represent both integers and floating-point values.
In this TypeScript tutorial, we will explore how to convert a string to a double in TypeScript using various methods.
Below are the three methods to convert a string to a double in TypeScript:
- Using the Unary Plus (+) Operator
- Using the Number() Constructor
- Using parseFloat()
For example, if the string is “21.44”, we will convert it to a double, then it returns 21.44 (without quotes).
Note that in TypeScript, integers, floating-point numbers, and double-precision floating-point numbers fall under the number data type.
Understanding Types in TypeScript
Let me first help you to understand that TypeScript doesn’t have a specific “double” type. Instead, TypeScript uses:
- number: Represents both integers and floating-point values
- string: Represents textual data
When we talk about converting to “double” in TypeScript, we’re talking about converting to the number type with decimal precision.
Convert String To Double Using Number() Constructor
Here we will see how to convert a string to a double in TypeScript using the number() constructor.
The number () constructor in TypeScript is used to convert a string to a number
For example, the string “22,44444” is passed to the number constructor, then it converts it to a parse floating point number.
In the code editor, create a file i.e. stringToDouble.ts, and then write the below code.
let strVal:string = "22.44444";
let numVal:number = Number(strVal);
console.log(numVal); // Output: 22.44444
To compile the below code, run the below command and you can see the result in the console:
ts-node stringToDouble.ts

This is an example of converting the string to a double in TypeScript using the Number () constructor.
Here is another example:
function convertWithNumberConstructor(str: string): number {
return Number(str);
}
// Usage examples
const amount = convertWithNumberConstructor("199.99"); // Returns 199.99
const negativeValue = convertWithNumberConstructor("-45.67"); // Returns -45.67
const invalid = convertWithNumberConstructor("12.34.56"); // Returns NaN
Check out Get String After Character In TypeScript
Convert A String To A Double in TypeScript Using parseFloat() Method
Here we will see how to convert the string to a double in TypeScript using the parseFloat() method.
The parseFloat() in TypeScript is used to parse the string and return the parsed floating-point number.
For example, we will take a string like below and by using parseFloat(), convert it into a parse floating point number or double
In the ‘stringToDouble.ts’ file write the below code:
let strVal:string = "22.44444";
let numVal :number = parseFloat(strVal);
console.log(numVal); // Output:22.44444
To compile the below code, run the below command, and you can see the result in the console:
ts-node stringToDouble.ts

This is an example of converting the string to a double in TypeScript using the parseFloat method.
Here is another example:
function convertWithParseFloat(str: string): number {
return parseFloat(str);
}
// Usage examples
const taxRate = convertWithParseFloat("7.25%"); // Returns 7.25
const measurement = convertWithParseFloat("42.5 inches"); // Returns 42.5
const invalid = convertWithParseFloat("dollars 99.95"); // Returns NaN
Check out TypeScript Check If String Is Number
Convert A String To A Double in TypeScript Using + Operator
Now, let me show you how to convert a string to a double in TypeScript using the + operator.
The + operator in TypeScript converts the string into a number. When we apply the + operator to a string, it converts the string to a number.
For example when we add + operator to the ‘22.44444’, then it converted to 22.44444.
In the ‘stringToDouble.ts’ file write the below code:
let strVal:string = "22.44444";
let numVal:number = +strVal;
console.log(numVal); // Output: 22.44444
To compile the code, run the command below, and you can see the result in the console.
ts-node stringToDouble.ts

This is an example of converting the string to a double in TypeScript using the + operator.
Let me show you another code and example.
function convertWithUnaryPlus(str: string): number {
return +str;
}
// Usage examples
const price = convertWithUnaryPlus("23.45"); // Returns 23.45
const temperature = convertWithUnaryPlus("-3.8"); // Returns -3.8
const invalid = convertWithUnaryPlus("$29.99"); // Returns NaN
Conclusion
In this typescript tutorial, we saw how to convert the string to double in typescript using different methods. These are:
- Using the number() constructor
- Using the parseFloat method
- Using the + operator
You may also like:
- TypeScript keyof with Strings
- Compare Strings in TypeScript
- Check If a String Is in an Enum in TypeScript
- Convert String to Number in TypeScript

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.