# Truncate a number to decimal places without rounding

Cut the decimal representation after a number of digits.

Canonical: https://1loc.dev/number/truncate-a-number-to-a-given-number-of-decimal-places-without-rounding/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function toFixedDown({ n, digits }) { return Number(`${n}`.match(new RegExp(`^-?\\d+(?:\\.\\d{0,${digits}})?`))[0]); }
```

## Input

```json
{
  "n": 25.198726354,
  "digits": 2
}
```

## Expected output

```json
25.19
```

## Edge case

Input:
```json
{
  "n": -1.999,
  "digits": 1
}
```
Output:
```json
-1.9
```

## Limits

- Works on the decimal string, so floating-point drift does not round the result up.
- Numbers that print in exponent form, such as 1e-7, are outside this contract.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/truncate-a-number-to-a-given-number-of-decimal-places-without-rounding.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: onelifemedia
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Keeps the string-matching variant and returns a number; rejects exponent notation. Original MDX retained as inert source evidence.
