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: don't excessively shorten_number #26760

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

barredterra
Copy link
Collaborator

@barredterra barredterra commented Jun 13, 2024

Reproduce

Create two Number Cards, "With decimals" and "Without decimals", calling these two custom methods:

import frappe


@frappe.whitelist()
def with_decimals(filters=None):
	return {
		"value": 1234.56789,
		"fieldtype": "Float",
	}


@frappe.whitelist()
def without_decimals(filters=None):
	return {
		"value": 1234.0,
		"fieldtype": "Float",
	}

Before

Bildschirmfoto 2024-06-14 um 15 39 28

The number with decimals is shortened to "1 K", losing 23.457 % in precision. The number without decimals remains unchanged.

Analysis

The call shorten_number(1234.56789, "Germany", 5) is expected to return a rough representation of the number (1234.56789), using less than 5 digits. This can already be achieved by rounding to the nearest integer.

After

Bildschirmfoto 2024-06-14 um 15 39 05

The number with decimals is rounded to the nearest integer, which is less than five digits, losing only 0.035 % in precision.

Before, `shorten_number(1234.5678, "Germany", 5)` wrongly returned `"1 K"`. Now it correctly returns `"1235"`, which is less than five digits.
@barredterra barredterra requested a review from ankush June 13, 2024 17:00
@barredterra barredterra added backport version-14-hotfix backport to version 14 backport version-15-hotfix Backport the PR to v15 labels Jun 13, 2024
@barredterra barredterra changed the title fix: shorten_number fix: don't excessively shorten_number Jun 13, 2024
@barredterra barredterra merged commit 639e340 into frappe:develop Jun 14, 2024
25 checks passed
@barredterra barredterra deleted the number_cards_shortening branch June 14, 2024 13:50
barredterra added a commit that referenced this pull request Jun 14, 2024
…-26760

fix: don't excessively shorten_number (backport #26760)
barredterra added a commit that referenced this pull request Jun 14, 2024
…-26760

fix: don't excessively shorten_number (backport #26760)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14 backport version-15-hotfix Backport the PR to v15
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant