Skip to content
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

Merged
merged 43 commits into from
Mar 26, 2024

Conversation

younies
Copy link
Member

@younies younies commented Dec 13, 2023

Implements CurrencyFormatter to handle 'short' and 'narrow' currency formatting patterns.

@younies younies requested a review from a team as a code owner December 13, 2023 17:38
@younies younies marked this pull request as draft December 13, 2023 17:38
@younies younies changed the title Implement CurrencyFormatter Implement end to end CurrencyFormatter for short and narrow formatting Mar 6, 2024
@younies younies marked this pull request as ready for review March 23, 2024 12:58
@younies younies requested a review from sffc March 23, 2024 12:58
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();
Copy link
Member Author

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?

Copy link
Member

@sffc sffc Mar 24, 2024

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).

Copy link
Member Author

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

@younies younies removed the request for review from a team March 26, 2024 13:20
sffc
sffc previously approved these changes Mar 26, 2024
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");
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

components/experimental/src/dimension/options.rs Outdated Show resolved Hide resolved
@younies younies merged commit 5febe65 into unicode-org:main Mar 26, 2024
30 checks passed
@younies younies deleted the currency-API branch March 26, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants