Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

fix 918 - Axis label rounding issues #919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdkh1311
Copy link

@mdkh1311 mdkh1311 commented Feb 8, 2019

Summary

Fix for #918

Solves

#918

@taoyouh
Copy link

taoyouh commented Apr 10, 2019

I think your solution is too complicated.
The problem here is the "rounding" isn't really a rounding. It's a truncation. You just need to change the Truncate to Round, and the problem will be solved.

@mdkh1311
Copy link
Author

mdkh1311 commented Apr 17, 2019

It's not so clear cut even with rounding however since to how many decimal places do you round to and what style of rounding do you use: AwayFromZero or ToEven? The signature of Math.Round is:

public static decimal Round (decimal d, int decimals, MidpointRounding mode);

I have a requirement to round to 4 decimal places, but I doubt other people do

@taoyouh
Copy link

taoyouh commented Apr 17, 2019

It's not so clear cut even with rounding however since to how many decimal places do you round to and what style of rounding do you use: AwayFromZero or ToEven? The signature of Math.Round is:

public static decimal Round (decimal d, int decimals, MidpointRounding mode);

I have a requirement to round to 4 decimal places, but I doubt other people do

In my PR #942 , if you set the "Unit" property, the algorithm will round the labels to make (labelValue / Unit) integral. You can round to any decimal places or even round to *.5 / *.0 if you like. I tested the case you mentioned in #918 and it works just as what you expected.

I think this is what the original algorithm intends to do, but 1) it only rounds the first label instead of every one, and 2) it used truncation instead of rounding.

I think the rounding style isn't important in this situation. The rounding is just for fixing the number very close to the target value, such as 0.999999->1 and I don't think AwayFromZero or ToEven matters.

@mdkh1311
Copy link
Author

Ah ok that makes sense. Thanks very much for finding a solution

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants