From 35ffb36fbdd33ae6f59dd6a88c7efca4a643d7c9 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 7 Jun 2021 23:46:39 +0200 Subject: [PATCH] Round amounts to the nearest integer rather than take the floor Signed-off-by: Yohann D'ANELLO --- apps/note/static/note/js/transfer.js | 2 +- note_kfet/static/js/base.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/note/static/note/js/transfer.js b/apps/note/static/note/js/transfer.js index cc2a7124..0ae76501 100644 --- a/apps/note/static/note/js/transfer.js +++ b/apps/note/static/note/js/transfer.js @@ -243,7 +243,7 @@ $('#btn_transfer').click(function () { error = true } - const amount = Math.floor(100 * amount_field.val()) + const amount = Math.round(100 * amount_field.val()) if (amount > 2147483647) { amount_field.addClass('is-invalid') $('#amount-required').html('' + gettext('The amount must stay under 21,474,836.47 €.') + '') diff --git a/note_kfet/static/js/base.js b/note_kfet/static/js/base.js index d7772a5a..34453824 100644 --- a/note_kfet/static/js/base.js +++ b/note_kfet/static/js/base.js @@ -7,8 +7,8 @@ * @returns {string} */ function pretty_money (value) { - if (value % 100 === 0) { return (value < 0 ? '- ' : '') + Math.floor(Math.abs(value) / 100) + ' €' } else { - return (value < 0 ? '- ' : '') + Math.floor(Math.abs(value) / 100) + '.' + + if (value % 100 === 0) { return (value < 0 ? '- ' : '') + Math.round(Math.abs(value) / 100) + ' €' } else { + return (value < 0 ? '- ' : '') + Math.round(Math.abs(value) / 100) + '.' + (Math.abs(value) % 100 < 10 ? '0' : '') + (Math.abs(value) % 100) + ' €' } }