From a9a2fe631461259909a5e0c7bbb94c8ef006fa09 Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Sat, 18 Aug 2018 21:08:56 -0500 Subject: [PATCH] Fixed mp rounding (#10599) * Fixed mp rounding * Fixed toFixed rounding --- website/client/mixins/notifications.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/website/client/mixins/notifications.js b/website/client/mixins/notifications.js index 7f6f26d07f..e492cb9c6f 100644 --- a/website/client/mixins/notifications.js +++ b/website/client/mixins/notifications.js @@ -2,6 +2,12 @@ import habiticaMarkdown from 'habitica-markdown'; import { mapState } from 'client/libs/store'; import { getDropClass, getXPMessage, getSign, round } from 'client/libs/notifications'; +// See https://stackoverflow.com/questions/4187146/truncate-number-to-two-decimal-places-without-rounding +function toFixedWithoutRounding (num, fixed) { + const re = new RegExp(`^-?\\d+(?:\.\\d{0,${(fixed || -1)}})?`); + return num.toString().match(re)[0]; +} + export default { computed: { ...mapState({notifications: 'notificationStore'}), @@ -46,7 +52,7 @@ export default { this.notify(parsedMarkdown, 'info'); }, mp (val) { - this.notify(`${this.sign(val)} ${this.round(val)}`, 'mp', 'glyphicon glyphicon-fire', this.sign(val)); + this.notify(`${this.sign(val)} ${toFixedWithoutRounding(val, 1)}`, 'mp', 'glyphicon glyphicon-fire', this.sign(val)); }, purchased (itemName) { this.text(this.$t('purchasedItem', {