-
Notifications
You must be signed in to change notification settings - Fork 735
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
bug: Unable to properly format currency #16480
Comments
The Here is an example of how you can use these functions: use ethnum::i256;
fn main() {
let num_128: i128 = 987654387909876;
let scale_128: u8 = 10;
let formatted_128 = display_decimal_128(num_128, scale_128);
println!("Formatted i128: ${}", formatted_128);
let num_256: i256 = i256::from(987654387909876);
let scale_256: u8 = 10;
let formatted_256 = display_decimal_256(num_256, scale_256);
println!("Formatted i256: ${}", formatted_256);
} This will output:
These functions ensure that the numeric values are correctly formatted with the specified number of decimal places, making them suitable for currency representation [1]. |
|
This gives us a string with 2 DP, but no thousand separator
|
I think the Rust num-format crate is probably what we want in this case. It takes a locale so the correct decimal and thousands separator are applied. |
we need to support more refer: |
Hi @inviscid , Is this okay?
|
@forsaken628 , looks good, would it also support below?
|
@rad-pat |
Search before asking
Version
v1.2.635-nightly
What's Wrong?
We have attempted multiple ways to use
to_char
to format numeric values into a suitable currency format but they all seem to fail.How to Reproduce?
Apply currency formatting to a numeric value like
9876.54387909876
in order to get something like$9,876.54
or$9.876,54
.Are you willing to submit PR?
The text was updated successfully, but these errors were encountered: