简体   繁体   中英

How to remove default space form console of printing number in JavaScript?

I am trying to solve online judge problems with JavaScript. I am facing a problem. When I am printing a number it is generating a space. But I don't want the space. Actually the online judge is not wanted the space.

Problem link: URI 1002

My JavaScript Code:

var R = parseFloat(readline());
var A = 3.14159 * (R * R);
console.log("A=", A.toFixed(4));

Here I am giving screenshots.

My output:

在此处输入图像描述

Here is space after the = sign.

Judge output:

在此处输入图像描述

That's because you're passing the 2 variables to console.log separately, separated with a comma.

Concatenate the string you're passing to the console :

console.log("A=" + A.toFixed(4));

@Cerbrus Answered your question

Another alternative would be to use template strings Instead of using the plus operator for concatenation do this:

console.log(`A=${A.toFixed(4)}`);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM