@@ -40,14 +40,23 @@ impl PartialOrd for Decimal {
4040
4141impl Display for Decimal {
4242 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
43+ let is_negative = self . data < ZERO . value ;
44+ let ( mut temp_q, mut temp_r) = ( & self . data ) . div_rem ( & self . precision_multiplier ) ;
45+
46+ if is_negative {
47+ f. write_str ( "-" ) ?;
48+ }
49+
50+ if temp_q < ZERO . value {
51+ temp_q = temp_q. neg ( ) ;
52+ }
53+ if temp_r < ZERO . value {
54+ temp_r = temp_r. neg ( ) ;
55+ }
4356 write ! (
4457 f,
45- "{}" ,
46- print_fixedp(
47- & self . data,
48- & self . precision_multiplier,
49- self . precision as usize ,
50- )
58+ "{temp_q}.{temp_r:0width$}" ,
59+ width = self . precision as usize
5160 )
5261 }
5362}
@@ -392,35 +401,6 @@ impl FixedPrecision for Decimal {
392401 }
393402}
394403
395- fn print_fixedp ( n : & IBig , precision : & IBig , width : usize ) -> String {
396- let ( mut temp_q, mut temp_r) = n. div_rem ( precision) ;
397-
398- let is_negative_q = temp_q < ZERO . value ;
399- let is_negative_r = temp_r < ZERO . value ;
400-
401- if is_negative_q {
402- temp_q = temp_q. abs ( ) ;
403- }
404- if is_negative_r {
405- temp_r = temp_r. abs ( ) ;
406- }
407-
408- let mut s = String :: new ( ) ;
409- if is_negative_q || is_negative_r {
410- s. push ( '-' ) ;
411- }
412- s. push_str ( & temp_q. to_string ( ) ) ;
413- s. push ( '.' ) ;
414- let r = temp_r. to_string ( ) ;
415- let r_len = r. len ( ) ;
416- // fill with zeroes up to width for the fractional part
417- if r_len < width {
418- s. push_str ( & "0" . repeat ( width - r_len) ) ;
419- }
420- s. push_str ( & r) ;
421- s
422- }
423-
424404struct Constant {
425405 value : IBig ,
426406}
0 commit comments