Skip to content

Commit

Permalink
fix: leading zero regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
iGroza committed Jun 28, 2024
1 parent 80985d1 commit ab53566
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@haqq/format-number-with-subscript-zeros",
"version": "1.0.0",
"version": "1.0.1",
"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.",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/formatNumberWithSubscriptZeros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function formatNumberWithSubscriptZeros(numberStr: string, presiction = 3
if (number >= min) {
const [part0, part1] = numberStr.split('.')
if(part1) {
const leadingZeros = part1?.match?.(/0+/)?.[0] || '';
const leadingZeros = part1?.match?.(/^0+/)?.[0] || '';
return `${part0}.${leadingZeros}${part1.replace(leadingZeros, '').slice(0, presiction)}`
}
return part1 ? [part0, part1.slice(0, presiction)].join('.') : part0;
Expand Down

0 comments on commit ab53566

Please sign in to comment.