-1

I'm trying to solve a challenge involving finding the mean of an array but the output must be a number with a decimal point (4.0) Is it possible to do this in JavaScript? if the answer is no is there a programming language that can do it

  • 1
    It wouldn't be a number any more if you wanted that output - it would be a string. – Andy Sep 20 '21 at 13:35
  • That challenge should be specifying the data type of the output: string or number? – Sebastian Simon Sep 20 '21 at 13:41
  • _“is there a programming language that can do it”_ isn’t really a useful question to ask. Don’t confuse the number _representation_ with the _number itself_, for any given number type. The literals `4.0` and `4` result in the same value JS. There are other programming languages, where they don’t, but a specific data type of a specific programming language should be specified. If not, either the challenge is very vague or your question is. And even if so, have you at least _tried_ passing that challenge with _any_ number representation? – Sebastian Simon Sep 20 '21 at 17:20

1 Answers1

0

you can use this

var num= 5;

num.toFixed(1);

it will return 5.0

Rahul_Mandhane
  • 187
  • 1
  • 11