Skip to content

Commit dde2269

Browse files
authored
Merge pull request #395 from reservoirprotocol/pedro/relay-5757-trailing-zeros
Remove trailing zeros
2 parents c45bb72 + aa034bd commit dde2269

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@reservoir0x/relay-kit-ui': patch
3+
---
4+
5+
Remove trailing zeros from formatted amount

packages/ui/src/utils/numbers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ function truncateBalance(balance: string) {
179179
* @param maxLength The maximum total length of the string representation.
180180
* @returns A plain string representation of the number, trimmed to the specified length.
181181
*/
182+
182183
function formatFixedLength(amount: string, maxLength: number) {
183184
if (!/^[-+]?\d*\.?\d*$/.test(amount)) return 'Invalid number'
184185

@@ -203,7 +204,10 @@ function formatFixedLength(amount: string, maxLength: number) {
203204
}
204205

205206
// Ensure no unnecessary trailing zeros and remove any trailing decimal points
206-
result = result.replace(/\.0+$/, '').replace(/\.$/, '')
207+
result = result
208+
.replace(/\.0+$/, '')
209+
.replace(/\.(\d*[^0])0+$/, '.$1')
210+
.replace(/\.$/, '')
207211

208212
// Add negative sign back if the number was negative
209213
if (isNegative) {

0 commit comments

Comments
 (0)