Fixed mp rounding (#10599)

* Fixed mp rounding

* Fixed toFixed rounding
This commit is contained in:
Keith Holliday 2018-08-18 21:08:56 -05:00 committed by GitHub
parent d6514bce8b
commit a9a2fe6314
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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', {