0

So, I have:

const Transaction = {
   all: [{
      description: 'Luz',
      amount: -50000,
      date: '23/01/2021',
   }, {
      description: 'Website',
      amount: 056,
      date: '23/01/2021',
   }, {
      description: 'Internet',
      amount: -25000,
      date: '23/01/2021',
   }, {
      description: 'App mobile',
      amount: 900000,
      date: '23/01/2021',
   }]
}

Then I print it on console without doing anything before it:

const App = {
   init() {
      Transaction.all.forEach((transaction) => {
         console.log(transaction)
      })
   }

The output is:

{description: "Luz", amount: -50000, date: "23/01/2021"}
{description: "Website", amount: 46, date: "23/01/2021"}
{description: "Internet", amount: -25000, date: "23/01/2021"}
{description: "App mobile", amount: 900000, date: "23/01/2021"}

Why Website amount(declared as 056) became 46??

romeucr
  • 169
  • 1
  • 13

1 Answers1

0

Because of the leading zero, the value is interpreted as an octal and then the value is converted to decimal.

Simply remove the leading zero to avoid the confusion.

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • Actually I need the initial zero because of some other treatment. I have solved it by defining like that: amount: Number('056'). I had no idea it could be related to octal. :D thanks! – romeucr Jan 29 '21 at 21:17