@@ -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,16 @@ 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 ! (
139+ 12345678901234567890123456789012345678_i128 ,
140+ 0 ,
141+ "12345678901234567890123456789012345678"
142+ ) ;
143+ assert_decimal_str_eq ! (
144+ 12345678901234567890123456789012345678_i128 ,
145+ 38 ,
146+ "0.123456789012"
147+ ) ;
161148
162149 // Negative cases
163150 assert_decimal_str_eq ! ( -110 , 3 , "-0.11" ) ;
@@ -166,6 +153,16 @@ mod tests {
166153 assert_decimal_str_eq ! ( -11 , 1 , "-1.1" ) ;
167154 assert_decimal_str_eq ! ( -11 , 0 , "-11" ) ;
168155 assert_decimal_str_eq ! ( -11 , -1 , "-110" ) ;
156+ assert_decimal_str_eq ! (
157+ -12345678901234567890123456789012345678_i128 ,
158+ 0 ,
159+ "-12345678901234567890123456789012345678"
160+ ) ;
161+ assert_decimal_str_eq ! (
162+ -12345678901234567890123456789012345678_i128 ,
163+ 38 ,
164+ "-0.123456789012"
165+ ) ;
169166
170167 // Round to 12 decimal places
171168 // 1.0000000000011 -> 1.000000000001
0 commit comments