@@ -23,7 +23,7 @@ public static class Utils
23
23
{
24
24
public const string AddressZero = "0x0000000000000000000000000000000000000000" ;
25
25
public const string NativeTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" ;
26
- public const double DECIMALS_18 = 1000000000000000000 ;
26
+ public const decimal DECIMALS_18 = 1000000000000000000 ;
27
27
28
28
public static string [ ] ToJsonStringArray ( params object [ ] args )
29
29
{
@@ -93,9 +93,9 @@ public static long UnixTimeNowMs()
93
93
94
94
public static string ToWei ( this string eth )
95
95
{
96
- if ( ! double . TryParse ( eth , NumberStyles . Number , CultureInfo . InvariantCulture , out double ethDouble ) )
96
+ if ( ! decimal . TryParse ( eth , NumberStyles . Number , CultureInfo . InvariantCulture , out decimal ethDecimal ) )
97
97
throw new ArgumentException ( "Invalid eth value." ) ;
98
- BigInteger wei = ( BigInteger ) ( ethDouble * DECIMALS_18 ) ;
98
+ BigInteger wei = ( BigInteger ) ( ethDecimal * DECIMALS_18 ) ;
99
99
return wei . ToString ( ) ;
100
100
}
101
101
@@ -106,15 +106,17 @@ public static string ToEth(this string wei, int decimalsToDisplay = 4, bool addC
106
106
107
107
public static string FormatERC20 ( this string wei , int decimalsToDisplay = 4 , int decimals = 18 , bool addCommas = true )
108
108
{
109
- decimals = decimals == 0 ? 18 : decimals ;
110
109
if ( ! BigInteger . TryParse ( wei , out BigInteger weiBigInt ) )
111
110
throw new ArgumentException ( "Invalid wei value." ) ;
112
- double eth = ( double ) weiBigInt / Math . Pow ( 10.0 , decimals ) ;
111
+
112
+ decimal eth = ( decimal ) weiBigInt / ( decimal ) Math . Pow ( 10 , decimals ) ;
113
113
string format = addCommas ? "#,0" : "#0" ;
114
+
114
115
if ( decimalsToDisplay > 0 )
115
116
format += "." ;
116
117
for ( int i = 0 ; i < decimalsToDisplay ; i ++ )
117
118
format += "#" ;
119
+
118
120
return eth . ToString ( format ) ;
119
121
}
120
122
@@ -652,9 +654,9 @@ public async static Task<GasPriceParameters> GetPolygonGasPriceParameters(int ch
652
654
return new GasPriceParameters ( GweiToWei ( data . fast . maxFee ) , GweiToWei ( data . fast . maxPriorityFee ) ) ;
653
655
}
654
656
655
- public static BigInteger GweiToWei ( double gweiAmount )
657
+ public static BigInteger GweiToWei ( decimal gweiAmount )
656
658
{
657
- return new BigInteger ( gweiAmount * 1e9 ) ;
659
+ return new BigInteger ( gweiAmount * 1_000_000_000m ) ; // 1e9 in decimal
658
660
}
659
661
660
662
public static string BigIntToHex ( this BigInteger number )
0 commit comments