@@ -6,20 +6,39 @@ namespace Sequence.Utils
66{
77 public static class DecimalNormalizer
88 {
9+ /// <summary>
10+ /// Normalize a float value into EVM-readable format
11+ /// </summary>
12+ /// <param name="x"></param>
13+ /// <param name="decimals"></param>
14+ /// <returns></returns>
915 public static string Normalize ( float x , int decimals = 18 )
1016 {
1117 BigInteger result = NormalizeAsBigInteger ( x , decimals ) ;
1218 return result . ToString ( ) ;
1319 }
1420
21+ /// <summary>
22+ /// Normalize a float value into EVM-readable format
23+ /// </summary>
24+ /// <param name="x"></param>
25+ /// <param name="decimals"></param>
26+ /// <returns></returns>
1527 public static BigInteger NormalizeAsBigInteger ( float x , int decimals = 18 )
1628 {
1729 x = Math . Abs ( x ) ;
1830 double normalized = x * Math . Pow ( 10 , decimals ) ;
1931 BigInteger result = ( BigInteger ) normalized ;
2032 return result ;
2133 }
22-
34+
35+ /// <summary>
36+ /// Return the value back into human-readable format
37+ /// Gives a string value - recommended for use in UI or anywhere where precision matters
38+ /// </summary>
39+ /// <param name="x"></param>
40+ /// <param name="decimals"></param>
41+ /// <returns></returns>
2342 public static string ReturnToNormalString ( BigInteger x , int decimals = 18 )
2443 {
2544 string numberStr = BigInteger . Abs ( x ) . ToString ( ) ;
@@ -42,11 +61,25 @@ public static string ReturnToNormalString(BigInteger x, int decimals = 18)
4261 return resultStr ;
4362 }
4463
64+ /// <summary>
65+ /// Return the value back into human-readable format
66+ /// Gives a float value - recommended for use during gameplay or anywhere where performance matters
67+ /// </summary>
68+ /// <param name="x"></param>
69+ /// <param name="decimals"></param>
70+ /// <returns></returns>
4571 public static float ReturnToNormal ( BigInteger x , int decimals = 18 )
4672 {
4773 return float . Parse ( ReturnToNormalString ( x , decimals ) ) ;
4874 }
4975
76+ /// <summary>
77+ /// Return the value back into human-readable format
78+ /// Gives a decimal value - recommended for use in UI or anywhere where precision matters
79+ /// </summary>
80+ /// <param name="x"></param>
81+ /// <param name="decimals"></param>
82+ /// <returns></returns>
5083 public static decimal ReturnToNormalPrecise ( BigInteger x , int decimals = 18 )
5184 {
5285 return decimal . Parse ( ReturnToNormalString ( x , decimals ) ) ;
0 commit comments