-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Truncate decimals when sending kaspa and krc20
- Loading branch information
1 parent
3f968ea
commit 8c0a033
Showing
6 changed files
with
86 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { truncateDecimals } from "./formatting" | ||
|
||
describe('truncateDecimals', () => { | ||
it('should return the whole number if no decimal', () => { | ||
const value = '1234' | ||
const decimals = 2 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('1234') | ||
}) | ||
|
||
it('should return the whole number if decimals is 0', () => { | ||
const value = '1234.56' | ||
const decimals = 0 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('1234') | ||
}) | ||
|
||
it('should remove decimal point if decimals = 0', () => { | ||
const value = '1234.' | ||
const decimals = 0 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('1234') | ||
}) | ||
|
||
it('should not remove decimal point if decimals > 0', () => { | ||
const value = '1234.' | ||
const decimals = 1 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('1234.') | ||
}) | ||
|
||
it('should return a truncated value with the specified number of decimals', () => { | ||
const value = '1234.5678' | ||
const decimals = 2 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('1234.56') | ||
}) | ||
|
||
it('should handle having no whole number', () => { | ||
const value = '.456' | ||
const decimals = 2 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('.45') | ||
}) | ||
|
||
it('should return "." if value is "."', () => { | ||
const value = '.' | ||
const decimals = 2 | ||
const result = truncateDecimals(value, decimals) | ||
expect(result).toBe('.') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters