-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement end to end CurrencyFormatter
for short and narrow formatting
#4452
Conversation
CurrencyFormatter
CurrencyFormatter
for short and narrow formatting
let fmt = CurrencyFormatter::try_new(&locale, Default::default()).unwrap(); | ||
let value = FixedDecimal::try_from("12345.67").unwrap(); | ||
let value = FixedDecimal::from("12345.67"); | ||
let value = FixedDecimal::try_from_f64(12345.67, FloatPrecision::Floating).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sffc , why there is no way to create FixedDecimal
in tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your function calls are not correct.
To create from a string, FixedDecimal implements FromStr, which has a method named from_str. You can also call parse() on a string.
To create from a float, you would need to enable the ryu feature (but you should prefer creating from ints or strings).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the illustration, I have used parse
let formatted_currency = fmt.format_fixed_decimal(&value, currency_code); | ||
let mut sink = String::new(); | ||
formatted_currency.write_to(&mut sink).unwrap(); | ||
assert_eq!(sink.as_str(), "$12345.67"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please file an issue about loading grouping separators and using fixeddecimalformatter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Shane F. Carr <[email protected]>
Implements
CurrencyFormatter
to handle 'short' and 'narrow' currency formatting patterns.