简体   繁体   English

如何删除 JavaScript 中打印编号的默认空格格式控制台?

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

I am trying to solve online judge problems with JavaScript.我正在尝试用 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问题链接: URI 1002

My JavaScript Code:我的 JavaScript 代码:

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

Here I am giving screenshots.这里我给出截图。

My output:我的 output:

在此处输入图像描述

Here is space after the = sign.这是=符号后的空格。

Judge output:法官output:

在此处输入图像描述

That's because you're passing the 2 variables to console.log separately, separated with a comma.那是因为您将 2 个变量分别传递给console.log ,用逗号分隔。

Concatenate the string you're passing to the console :连接您传递给console的字符串:

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

@Cerbrus Answered your question @Cerbrus 回答了你的问题

Another alternative would be to use template strings Instead of using the plus operator for concatenation do this:另一种选择是使用模板字符串而不是使用加号运算符进行连接,请执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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