(&self, num: f64)
| 493 | } |
| 494 | |
| 495 | pub fn format_float(&self, num: f64) -> String { |
| 496 | let sign_string = if num.is_sign_negative() && !num.is_nan() { |
| 497 | "-" |
| 498 | } else { |
| 499 | self.flags.sign_string() |
| 500 | }; |
| 501 | |
| 502 | let precision = match &self.precision { |
| 503 | Some(CFormatPrecision::Quantity(quantity)) => match quantity { |
| 504 | CFormatQuantity::Amount(amount) => *amount, |
| 505 | CFormatQuantity::FromValuesTuple => 6, |
| 506 | }, |
| 507 | Some(CFormatPrecision::Dot) => 0, |
| 508 | None => 6, |
| 509 | }; |
| 510 | |
| 511 | let CFormatType::Float(format_type) = self.format_type else { |
| 512 | unreachable!() |
| 513 | }; |
| 514 | |
| 515 | let magnitude = num.abs(); |
| 516 | let case = format_type.case(); |
| 517 | |
| 518 | let magnitude_string = match format_type { |
| 519 | CFloatType::PointDecimalLower | CFloatType::PointDecimalUpper => float::format_fixed( |
| 520 | precision, |
| 521 | magnitude, |
| 522 | case, |
| 523 | self.flags.contains(CConversionFlags::ALTERNATE_FORM), |
| 524 | ), |
| 525 | CFloatType::ExponentLower | CFloatType::ExponentUpper => float::format_exponent( |
| 526 | precision, |
| 527 | magnitude, |
| 528 | case, |
| 529 | self.flags.contains(CConversionFlags::ALTERNATE_FORM), |
| 530 | ), |
| 531 | CFloatType::GeneralLower | CFloatType::GeneralUpper => { |
| 532 | let precision = if precision == 0 { 1 } else { precision }; |
| 533 | float::format_general( |
| 534 | precision, |
| 535 | magnitude, |
| 536 | case, |
| 537 | self.flags.contains(CConversionFlags::ALTERNATE_FORM), |
| 538 | false, |
| 539 | ) |
| 540 | } |
| 541 | }; |
| 542 | |
| 543 | if self.flags.contains(CConversionFlags::ZERO_PAD) { |
| 544 | let fill_char = if !self.flags.contains(CConversionFlags::LEFT_ADJUST) { |
| 545 | '0' |
| 546 | } else { |
| 547 | ' ' |
| 548 | }; |
| 549 | format!( |
| 550 | "{}{}", |
| 551 | sign_string, |
| 552 | self.fill_string( |
nothing calls this directly
no test coverage detected