Groovy Calcuution与javascript相同吗?
我的程序中的Groovy Calcuution与javascript相同吗?,java,javascript,groovy,Java,Javascript,Groovy,我的程序中的Groovy计算出了什么问题 public class GroovyRunner { public static void main(String[] args) throws Exception { new GroovyShell().parse(new File("hello.groovy")).invokeMethod("show", null); } } 你好,groovy def show() { float a = 0.1;
Groovy
计算出了什么问题
public class GroovyRunner {
public static void main(String[] args) throws Exception {
new GroovyShell().parse(new File("hello.groovy")).invokeMethod("show", null);
}
}
你好,groovy
def show() {
float a = 0.1;
float c = 0.1;
float d = 0.2;
if(a + c == d) {
println "Equal"
} else {
println "Not Equal"
}
}
The result is `Equal`
def show() {
float a = 0.1;
float c = 0.2;
float d = 0.3;
if(a + c == d) {
println "Equal"
} else {
println "Not Equal"
}
}
当我更改c
和d
变量的值时,如下所示。结果是不相等
你好,groovy
def show() {
float a = 0.1;
float c = 0.1;
float d = 0.2;
if(a + c == d) {
println "Equal"
} else {
println "Not Equal"
}
}
The result is `Equal`
def show() {
float a = 0.1;
float c = 0.2;
float d = 0.3;
if(a + c == d) {
println "Equal"
} else {
println "Not Equal"
}
}
我决定使用Groovy
,因为我想避免Javascript
引擎的浮点计算。Groovy计算为
Javascript
?,而不是:
float a = 0.1;
float c = 0.2;
float d = 0.3;
使用:
Groovy将自动处理并提供正确的结果。@Cerbrus,实际上,我想将计算过程配置为
script
file。但是,我的要求是不要使用javascript计算。如何使用java
calculation作为scipt文件配置?