mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-17 19:42:15 +00:00
Fixed mp rounding (#10599)
* Fixed mp rounding * Fixed toFixed rounding
This commit is contained in:
parent
d6514bce8b
commit
a9a2fe6314
1 changed files with 7 additions and 1 deletions
|
|
@ -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', {
|
||||
|
|
|
|||
Loading…
Reference in a new issue