@@ -106,30 +106,7 @@ pub(crate) fn big_decimal_to_str(value: BigDecimal) -> String {
106106 // Round the value to limit the number of decimal places
107107 let value = value. round ( 12 ) . normalized ( ) ;
108108 // Format the value to a string
109- format_big_decimal ( value)
110- }
111-
112- fn format_big_decimal ( value : BigDecimal ) -> String {
113- let ( integer, scale) = value. into_bigint_and_exponent ( ) ;
114- let mut str = integer. to_str_radix ( 10 ) ;
115- if scale <= 0 {
116- // Append zeros to the right of the integer part
117- str. extend ( std:: iter:: repeat ( '0' ) . take ( scale. unsigned_abs ( ) as usize ) ) ;
118- str
119- } else {
120- let ( sign, unsigned_len, unsigned_str) = if integer. is_negative ( ) {
121- ( "-" , str. len ( ) - 1 , & str[ 1 ..] )
122- } else {
123- ( "" , str. len ( ) , & str[ ..] )
124- } ;
125- let scale = scale as usize ;
126- if unsigned_len <= scale {
127- format ! ( "{}0.{:0>scale$}" , sign, unsigned_str)
128- } else {
129- str. insert ( str. len ( ) - scale, '.' ) ;
130- str
131- }
132- }
109+ value. to_plain_string ( )
133110}
134111
135112#[ cfg( test) ]
@@ -158,6 +135,8 @@ mod tests {
158135 assert_decimal_str_eq ! ( 11 , 0 , "11" ) ;
159136 assert_decimal_str_eq ! ( 11 , -1 , "110" ) ;
160137 assert_decimal_str_eq ! ( 0 , 0 , "0" ) ;
138+ assert_decimal_str_eq ! ( 12345678901234567890123456789012345678_i128 , 0 , "12345678901234567890123456789012345678" ) ;
139+ assert_decimal_str_eq ! ( 12345678901234567890123456789012345678_i128 , 38 , "0.123456789012" ) ;
161140
162141 // Negative cases
163142 assert_decimal_str_eq ! ( -110 , 3 , "-0.11" ) ;
@@ -166,6 +145,8 @@ mod tests {
166145 assert_decimal_str_eq ! ( -11 , 1 , "-1.1" ) ;
167146 assert_decimal_str_eq ! ( -11 , 0 , "-11" ) ;
168147 assert_decimal_str_eq ! ( -11 , -1 , "-110" ) ;
148+ assert_decimal_str_eq ! ( -12345678901234567890123456789012345678_i128 , 0 , "-12345678901234567890123456789012345678" ) ;
149+ assert_decimal_str_eq ! ( -12345678901234567890123456789012345678_i128 , 38 , "-0.123456789012" ) ;
169150
170151 // Round to 12 decimal places
171152 // 1.0000000000011 -> 1.000000000001
0 commit comments