Fixed mp rounding (#10599)
* Fixed mp rounding * Fixed toFixed rounding
This commit is contained in:
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user