1

I am trying to get an integer from a JSON and multiply it with a number that has an exponentiation. However, it gives me

let dec = 10 ** _decimals;

SyntaxError: Unexpected token *

The code is the following:

let dec = 10 ** _decimals;
let value = parseInt(req.body.burn_value) * dec;

I can't figure out why it is doing that. What am I doing wrong?

5
  • 5
    ** is not multiplication -> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Mar 28, 2018 at 14:25
  • 1
    You could use Math.pow, for example; Math.pow(10, _decimals) Commented Mar 28, 2018 at 14:26
  • Can't see any JSON here, let dec = 10 ** _decimals; looks like JavaScript. Commented Mar 28, 2018 at 14:34
  • 1
    also There's no such thing as a "JSON Object" Commented Mar 28, 2018 at 14:35
  • Yeah, my bad. Too tired to write properly :S Commented Mar 28, 2018 at 16:09

1 Answer 1

8

Your environment doesn't support the new-ish exponentiation operator. But if you're just trying to multiply it, use * instead:

let dec = 10 * _decimals;

Or if you are trying to use exponentiation:

let dec = Math.pow(10, _decimals);
Sign up to request clarification or add additional context in comments.

2 Comments

The ** is a 'to the power of' operator, so 10 ** 2 is 100, not 20.
Now your args are the wrong way around in the Math.pow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.