Skip to content

Commit ab53566

Browse files
author
iGroza
committed
fix: leading zero regexp
1 parent 80985d1 commit ab53566

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@haqq/format-number-with-subscript-zeros",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A library to format numbers using scientific notation with subscript zeros. This method is particularly useful for representing very small numbers in a compact and readable format.",
55
"main": "dist/index.js",
66
"scripts": {

src/formatNumberWithSubscriptZeros.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function formatNumberWithSubscriptZeros(numberStr: string, presiction = 3
1111
if (number >= min) {
1212
const [part0, part1] = numberStr.split('.')
1313
if(part1) {
14-
const leadingZeros = part1?.match?.(/0+/)?.[0] || '';
14+
const leadingZeros = part1?.match?.(/^0+/)?.[0] || '';
1515
return `${part0}.${leadingZeros}${part1.replace(leadingZeros, '').slice(0, presiction)}`
1616
}
1717
return part1 ? [part0, part1.slice(0, presiction)].join('.') : part0;

0 commit comments

Comments
 (0)