Skip to content

Commit

Permalink
Fixed mp rounding (#10599)
Browse files Browse the repository at this point in the history
* Fixed mp rounding

* Fixed toFixed rounding
  • Loading branch information
TheHollidayInn committed Aug 19, 2018
1 parent d6514bc commit a9a2fe6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion website/client/mixins/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit a9a2fe6

Please sign in to comment.