[Vuejs]-ToFixed() a large number in a template VueJS

0👍

toFixed() is returning a string and not a number.
For better readability I would extract the logic in an own function aswell

EDIT: added Math
instead of toFixed you could write a function which transform your number into a decimal.

const transformNumber = (number) => {
  return Math.trunc(number * 10000)/10000;
}

and like mentioned a computed property:

computed: {
  reward(): {
    return transformNumber(myAcccount.reward.accrued) * (10 ** -9) - transformNumber(appAcccount.reward.paid) * (10 ** -9)
  }
}

0👍

You can try applying .toFixed() to the end of the calculation by enclosing the math part inside ().

<div class="mb-2">Reward: {{ (myAcccount.reward.accrued * (10 ** -9) - appAcccount.reward.paid * (10 ** -9)).toFixed(4)}}</div>

Leave a comment