@@ -112,9 +112,7 @@ export function FundWallet({
112112 // Convert USD amount to token amount using token price
113113 const tokenAmount = usdAmount / uiOptions . destinationToken . priceUsd ;
114114 // Format to reasonable decimal places (up to 6 decimals, remove trailing zeros)
115- const formattedAmount = Number . parseFloat (
116- tokenAmount . toFixed ( 6 ) ,
117- ) . toString ( ) ;
115+ const formattedAmount = toPlainString ( Number . parseFloat ( tokenAmount . toFixed ( 6 ) ) ) ;
118116 setAmount ( formattedAmount ) ;
119117 } ;
120118
@@ -341,3 +339,36 @@ export function FundWallet({
341339 </ WithHeader >
342340 ) ;
343341}
342+
343+ function toPlainString ( num : number ) {
344+ const str = num . toString ( ) ;
345+
346+ // If no exponential notation, return as-is
347+ if ( str . indexOf ( 'e' ) === - 1 ) {
348+ return str ;
349+ }
350+
351+ // Parse exponential notation
352+ const parts = str . split ( 'e' ) ;
353+ const coefficient = parts [ 0 ] ;
354+ const exponent = parseInt ( parts [ 1 ] ?? '0' ) ;
355+
356+ // Handle negative exponents (small numbers)
357+ if ( exponent < 0 ) {
358+ const zeros = '0' . repeat ( Math . abs ( exponent ) - 1 ) ;
359+ const digits = coefficient ?. replace ( '.' , '' ) || '' ;
360+ return '0.' + zeros + digits ;
361+ }
362+
363+ // Handle positive exponents (large numbers)
364+ const [ integer , decimal = '' ] = coefficient ?. split ( '.' ) || [ ] ;
365+ const zerosNeeded = exponent - decimal . length ;
366+
367+ if ( zerosNeeded >= 0 ) {
368+ return integer + decimal + '0' . repeat ( zerosNeeded ) ;
369+ } else {
370+ const insertAt = ( integer ?. length ?? 0 ) + zerosNeeded ;
371+ const result = integer + decimal ;
372+ return result . slice ( 0 , insertAt ) + '.' + result . slice ( insertAt ) ;
373+ }
374+ }
0 commit comments