matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.89k stars 2.65k forks source link

show always same number of decimal digits - even if "0" #10298

Open hpvd opened 8 years ago

hpvd commented 8 years ago

Show always same number of decimal digits (123.X) - even if "0" otherways having no decimal digits on may think these values are rounded in another way...

hmm thought this was already solved some time ago?

Please see attachements

2016-07-13_10h28_27

2016-07-13_10h31_14

tsteur commented 8 years ago

👍

tsteur commented 8 years ago

this visualization may use a custom template so it might not have been solved there, just a guess

hpvd commented 8 years ago

looking again at the screenshots above, just found another tiny issues: alignment broken in movers and shakers widget #10308

obax commented 7 years ago

I can make this quick fix. Would you assign this to me?

mattab commented 7 years ago

Hi @obax we don't assign issues, you can just create a Pull Request and reference this one :+1:

Morerice commented 7 years ago

In NumberFormatter::formatNumberWithPattern() there is this snippet in the final parts of the function, which ensures that the number does at least have the minimum number of fraction digits:

if ($minimumFractionDigits < $maximumFractionDigits) {
    // Strip any trailing zeroes.
    $minorDigits = rtrim($minorDigits, '0');
    if (strlen($minorDigits) < $minimumFractionDigits) {
        // Now there are too few digits, re-add trailing zeroes
        // until the desired length is reached.
        $neededZeroes = $minimumFractionDigits - strlen($minorDigits);
        $minorDigits .= str_repeat('0', $neededZeroes);
    }
}

Currently, if the minimum and maximum digits are equal, this is not executed and the value is rounded based on the maximum using the round() function.

The special case arises when the round() function has a whole number as its first parameter because this function does not add the decimal points. I'm guessing this was known when the formatter was developed because of this test in NumberFormatterTest: ('en', -50, 3, 3, '-50%').

Imo if the minimum = maximum it implies that the decimal point accuracy should be exactly as the number provided: ('en', -50, 3, 3, '-50.000%'). Would you agree with this?