Have you ever needed to round down a number to two decimal places in TypeScript? You may need this when working with currency values (such as US dollars and cents), or you may need to ensure that calculations for tax or discounts.
In this tutorial, I will explain how to round down to 2 decimals in TypeScript using various methods, including using Math.floor, toFixed, and a custom utility function with examples.
Let me first provide an example of why we need to round down to 2 decimal places in TypeScript.
If you’re working with financial data—such as calculating sales tax, discounts, or invoice totals—precision is crucial. For example, you might want to display $19.999 as $19.99, not $20.00. Rounding down (also called “flooring”) ensures you never accidentally overcharge your customers due to floating-point quirks.
JavaScript (and by extension, TypeScript) doesn’t have a built-in function to round down to a specific number of decimal places, but with a few tricks, we can achieve exactly what we need.
Here are the methods to round down to 2 decimals in TypeScript.
Method 1: Using Math.floor() for Rounding Down
The most reliable way I’ve found to round down to two decimal places in TypeScript is to use the Math.floor function. Here’s how it works:
Step-by-Step:
- Multiply your number by 100 (to shift the decimal two places to the right).
- Apply
Math.floorto remove anything after the decimal. - Divide the result by 100 to shift the decimal back.
Example:
Here is an example.
function roundDownToTwoDecimals(num: number): number {
return Math.floor(num * 100) / 100;
}
// Usage
const price = 19.999;
const rounded = roundDownToTwoDecimals(price);
console.log(rounded); // Output: 19.99
You can see the exact output in the screenshot below:

How it works:
19.999 * 100 = 1999.9Math.floor(1999.9) = 19991999 / 100 = 19.99
This method always rounds down—never up—making it perfect for financial calculations.
Check out TypeScript ?? Operator
Method 2: Using toFixed() (and Why It’s Not Always Enough)
Many developers try to use .toFixed(2) to round numbers to two decimals in TypeScript. While this works for formatting, it doesn’t always round down. Instead, it rounds to the nearest value.
Example:
Here is an example.
const price = 19.999;
console.log(price.toFixed(2)); // Output: "20.00" (as a string)
You can see the exact output in the screenshot below:

Important:
.toFixed(2)returns a string, not a number.- It rounds to the nearest value, not always down.
When to use:
- When you only care about displaying the value (e.g., on a UI), not for calculations.
- If you must always round down, use
Math.flooras shown above.
Check out How to Convert TypeScript Objects to JSON
Method 3: Create a Custom Round Down Function
Sometimes, you might want a reusable utility function that lets you specify the number of decimal places to round down to. Here’s a flexible approach I use in my projects:
function roundDown(num: number, decimals: number = 2): number {
const factor = Math.pow(10, decimals);
return Math.floor(num * factor) / factor;
}
// Usage
console.log(roundDown(123.4567, 2)); // 123.45
console.log(roundDown(123.4567, 3)); // 123.456
You can see the exact output in the screenshot below:

Why I like this:
- Works for any number of decimals.
- Easy to reuse across your codebase.
Read How to Compare String to Enum in TypeScript
Handle Negative Numbers
One thing to keep in mind: Math.floor always rounds towards negative infinity. This means that for negative numbers, it will make them more negative.
Example:
console.log(roundDownToTwoDecimals(-19.991)); // Output: -19.99
console.log(roundDownToTwoDecimals(-19.999)); // Output: -20.00
If you need to always round towards zero (truncate), you can use Math.trunc:
function truncateToTwoDecimals(num: number): number {
return Math.trunc(num * 100) / 100;
}
console.log(truncateToTwoDecimals(-19.999)); // Output: -19.99
Check out Push Objects into an Array in TypeScript
Round Down to 2 Decimals in TypeScript Examples
Now, let me show you some examples of rounding down to 2 decimals in TypeScript.
1. Calculate Sales Tax (Always Round Down)
Suppose you’re building a shopping cart for a US-based e-commerce site. You need to calculate the sales tax and always round down to avoid overcharging.
const subtotal = 49.99;
const taxRate = 0.0725; // 7.25% (California sales tax)
const tax = roundDownToTwoDecimals(subtotal * taxRate);
console.log(`Tax: $${tax}`); // Output: Tax: $3.61
2. Discount Calculations
If you’re applying a 15% discount and want to always round down:
const originalPrice = 120.00;
const discountRate = 0.15;
const discount = roundDownToTwoDecimals(originalPrice * discountRate);
const finalPrice = originalPrice - discount;
console.log(`Final Price: $${finalPrice}`); // Output: Final Price: $102.00
3. Invoice Totals
When generating invoices, always round down the total:
const items = [19.99, 5.49, 3.75];
const total = roundDownToTwoDecimals(items.reduce((sum, item) => sum + item, 0));
console.log(`Invoice Total: $${total}`); // Output: Invoice Total: $29.23
Conclusion
In this tutorial, I explained how to round down to two decimal places in TypeScript using various methods, such as using Math.floor, a custom function, or formatting with .toFixed for display.
If you found this tutorial helpful, feel free to bookmark it for future reference. And if you have any questions or encounter challenges, please don’t hesitate to leave a comment below—I’m always happy to help!
You may also like the following tutorials:
- Get String Between 2 Characters In TypeScript
- Convert String To Double In TypeScript
- Get String After Character In TypeScript
- TypeScript Check If String Is Number

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.