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
Shouldn't Amount
handle decimals formatting with {:.8}
?
#2136
Comments
Seems like a reasonable expectation. |
Definitely a bug since we intended fully working formatting in |
I had a quick look at this bug, and it seems like the precision is not respected at all:
stdout:
Also, the tests surrounding this all call macros, which I think could be simplified to helper functions. |
Oh, now I remembered we purposely ignore precision because it'd cut off significant digits which is pretty bad in a financial application. But cutting zeros should be allowed. |
Hmm well maybe panic or something if precision is used, because silently working may be disastrous if there's an assumption the precision is working.
in the bug stated above, it looks like the zero is cut when it should not be. |
Oh, yeah, maybe panic for precision < 8 to be precise.
Crap, my mind is broken today, sorry about that! So yeah - no precision means infinite precision - don't panic, precision 0..8 - panic, precision 8+ - add zeroes. |
If I ask any spreadsheet to format The use case is putting bitcoin amounts in a text table so that you can read numbers in colums. I can get away with just If this is not acceptable, maybe one idea is using the alternate repr for that, eg |
I agree. |
I was thinking about having |
I think that's too confusing and undiscoverable. The precision modifier has an expected behavior (which includes dropping data) and we should just follow that behavior. |
Hmm, I guess you're right. |
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if the Amount is not precision specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase are also added to for changes introduced. Resolves: rust-bitcoin#2136
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if the Amount is not precision specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase are also added to for changes introduced. Resolves: rust-bitcoin#2136 implement clippy recommendations
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if the Amount is not precision specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase are also added to for changes introduced. Resolves: rust-bitcoin#2136
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if a precision on the Amount is not specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase is added to for changes introduced. Resolves: rust-bitcoin#2136
It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if a precision on the Amount is not specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase is added to for changes introduced. Resolves: rust-bitcoin#2136
d887423 Enforce displaying Amount with trailing zeros (448 OG) Pull request description: It is common to display bitcoins using trailing zeros upto 8 decimals. This commit enforces: - Displaying Amount in BTC with trailing zeroes by eight decimal places if a precision on the Amount is not specified. - Displaying Amount in BTC upto the precision specified truncating the insignificant zeros. - Displaying amount in BTC without any decimals if the remainder of the amount divided by the satoshis in 1 BTC is equal to zero using formula `satoshis.rem_euclid(Amount::ONE_BTC.to_sat()) != 0` These are not breaking changes and all previous tests pass. A testcase is added to for changes introduced. Resolves: #2136 ACKs for top commit: sanket1729: ACK d887423 apoelstra: ACK d887423 Tree-SHA512: c32e41216477f60a8d95f164bf4a1f6644ea14adc7e169743ce419b0f26ecb6603f3a516f9b18d6508c04ce658f6a0a78ff3b0b062aeb7101b28bbb1e9d522bc
#2604 solve the issue as described in the first message. However, it's not "doing like a spreedsheet" when I ask n digits. In other words, the following fails:
|
Let's re-open the issue. #2604 was by a new contributor who deliberately didn't break any existing tests (which I appreciate) but maybe we need to be more aggressive. |
How would this be handled? Would a new method to handle precision with truncating insignificant zeroes suffice? Maybe something like |
No, we don't need a new method. The existing |
Thanks! I would like to solve this. Will follow up for more questions if I don't fully understand the task |
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Just like the existing code, no width is added if there exists fractional values exist just like the existing code works. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Replaces self.fmt_value_in() with fmt_satoshi_in() so that FomartOptions is not made public which would be the requirements if self.fmt_value_in() is used. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Replaces self.fmt_value_in() with fmt_satoshi_in() so that FomartOptions is not made public which would be the requirements if self.fmt_value_in() is used. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Replaces self.fmt_value_in() with fmt_satoshi_in() so that FomartOptions is not made public which would be the requirements if self.fmt_value_in() is used. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Replaces self.fmt_value_in() with fmt_satoshi_in() so that FomartOptions is not made public which would be the requirements if self.fmt_value_in() is used. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Replaces self.fmt_value_in() with fmt_satoshi_in() so that FomartOptions is not made public which would be the requirements if self.fmt_value_in() is used. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
All characters beyond the needed precision are truncated In the case of a SignedAmount the default precision is now 8 just like the Amount Replaces self.fmt_value_in() with fmt_satoshi_in() so that FomartOptions is not made public which would be the requirements if self.fmt_value_in() is used. Tests have been improved to handle precision Resolves: rust-bitcoin#2136
I would expect this to work
While it fails with:
The text was updated successfully, but these errors were encountered: