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??

2
  • 3
    056 is octal which converts to 46 decimal. Commented Jan 29, 2021 at 21:06
  • thanks VLAZ I had no idea of that and solved the issue declaring amount: Number('056') Commented Jan 29, 2021 at 21:17

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.