cap answer buttons to 1 decimal place

we can switch to NUMBER() instead in the future, but will need
to update all the translations at the same time
This commit is contained in:
Damien Elmes 2020-02-25 13:21:26 +10:00
parent c58b4158a7
commit b1a192b384
3 changed files with 5 additions and 4 deletions

View File

@ -516,7 +516,7 @@ def test_nextIvl():
assert ni(c, 3) == 21600000
# (* 100 2.5 1.3 86400)28080000.0
assert ni(c, 4) == 28080000
assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.83mo"
assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.8mo"
def test_misc():

View File

@ -613,7 +613,7 @@ def test_nextIvl():
assert ni(c, 3) == 21600000
# (* 100 2.5 1.3 86400)28080000.0
assert ni(c, 4) == 28080000
assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.83mo"
assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.8mo"
def test_bury():

View File

@ -7,8 +7,9 @@ use crate::i18n::{tr_args, FString, I18n};
pub fn answer_button_time(seconds: f32, i18n: &I18n) -> String {
let span = Timespan::from_secs(seconds).natural_span();
let amount = match span.unit() {
TimespanUnit::Months | TimespanUnit::Years => span.as_unit(),
// we don't show fractional values except for months/years
// months/years shown with 1 decimal place
TimespanUnit::Months | TimespanUnit::Years => (span.as_unit() * 10.0).round() / 10.0,
// other values shown without decimals
_ => span.as_unit().round(),
};
let args = tr_args!["amount" => amount];