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

FIX: when qty is not an integer, apply price() #31138

Conversation

atm-florianm
Copy link
Contributor

@atm-florianm atm-florianm commented Sep 26, 2024

FIX: weird qty shown

Issue

Currently, the report cabyprodserv.php displays the quantity column as is:

print $qty[$key];

Some companies use non-integer quantities.
Due to the non-infinite precision of binary representation and arithmetic, floats can sometimes be counter-intuitive.

> ini_set('precision', -1);
> echo 0.1 + 0.2;
0.30000000000000004

One of our customers has this problem (weird quantities such as 7.600000000000001 appear on screen). Using price() when the number has non-zero decimals seems to work and enables the customer to better control how the decimals are displayed.

…ecision errors if php.ini's precision settings are too high
@@ -425,7 +425,7 @@

// Quantity
print '<td class="right">';
print $qty[$key];
print $qty[$key] == round($qty[$key]) ? $qty[$key] : price($qty[$key]);
Copy link
Member

@eldy eldy Sep 26, 2024

Choose a reason for hiding this comment

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

Why not doing
price($qty[$key], 1, $langs, 0, 0);
all the time ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this is way better indeed.

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Sep 26, 2024
@eldy eldy merged commit c727bbb into Dolibarr:10.0 Sep 26, 2024
1 of 2 checks passed
@atm-florianm atm-florianm deleted the FIX_125_DA025540_cabyprodserv_display_floating_point_qty_nicely branch September 27, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Some questions or discussions are opened and wait answers of author or other people to be processed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants