Skip to content

Commit

Permalink
Treat '.' as zero
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Jul 16, 2024
1 parent 76fc135 commit 18fee6b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: Treat '.' as zero

## 4.2.2 (2024-07-15)

- fixed: Update validate regex to exclude hex strings, integers and floats
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const round = (x1: string | number, precision: number): string =>

export function toBns(n: number | string): string {
let out = typeof n === 'number' ? n.toString() : n.replace(/^\s+|\s+$/g, '')
if (out === '') {
if (out === '' || out === '.') {
out = '0'
}

Expand Down
3 changes: 3 additions & 0 deletions test/biggystring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ describe('toBns', function () {
it('2 spaces', function () {
assert.equal(toBns(' '), '0')
})
it('decimal only', function () {
assert.equal(toBns('.'), '0')
})
it('scientific notation: regular numbers', function () {
const numStr = '5e0'
assert.equal(toBns(numStr), '5')
Expand Down

0 comments on commit 18fee6b

Please sign in to comment.