jaredlyon / JareBot

A revisited JS project
GNU General Public License v3.0
5 stars 1 forks source link

Balance Module Expresses Negative Values #6

Closed jaredlyon closed 5 years ago

jaredlyon commented 5 years ago

image

Due to the current structure of the bank.json file, account balances are expressed as floats, allowing for them to reach extremely small values, yet still remain negative (i.e. -0.000000001424 -> $-0.00).

Currently, the three possible solutions are:

  1. Write an interval function in func.js that cuts off all account balance values stored in bank.json to the hundredths place.
  2. Restructure existing functions such that account balances are no longer stored as floats.
  3. Edit the balance.js module such that these values are always returned as a 'positive' zero, i.e. returning the absolute value of the account balances.
jaredlyon commented 5 years ago

Added a Math.abs() function when defining the returned variable:

module.exports = {
  name: 'balance',
  permission: 1,
  main: function(bot, msg) {
    let balance = Number(bot.bank[msg.author.id].balance)
    let absbalance = Math.abs(balance)
    msg.reply(`your balance is **$${absbalance.toFixed(2)}**!`);
  }
};

Results: image