javascript - GWT Compiler: Adding two numbers is creating a string -


i have code, goal being, take numbers, , give me number. easy enough.

private final int height = 5;  private double interpolatedoubleproperty(     int heightatlower, int heightathigher,      //4, 10     double lowvalue, double highvalue)          //1, 0 {             double lowtohighdelta = heightathigher - heightatlower;          // 6 = 10 - 4             double lowtothisdelta = (double)this.height    - heightatlower;  // 1 = 5 - 4             double lerpratio = lowtothisdelta / lowtohighdelta;              // 0.17  = 1 / 6             double valuedelta = highvalue - lowvalue;                        // -1 = 0 - 1     double increment = lerpratio * valuedelta;                       // -0.17 = 0.17 * -1     double toreturn = lowvalue + increment;                          // 0.83 = 1 + -0.17      gwt.log("interpolated value = " + toreturn);      return toreturn; } 

however, returned value i'm getting bad. case (see comments input values) gwt log output is:

interpolated value = 1-0.16666666666666666

which tells me "toreturn" getting treated string, it's value being equal concatenation of "lowvalue" , "increment".

this gwt, whatever java code i'm writing here getting compiled js, , @ point value getting mistakenly cast string. causing this? anyway resolve it? i'm using gwt v2.6.

bear naming, lowvalue , highvalue , indeed supposed 1 , 0 respectively.

solved it:

the variable lowvalue coming field being set html slider created , managed jsni code:

private static native double getslidervalue(string sliderid) /*-{     return $doc.getelementbyid(sliderid).value;        }-*/; 

after compilation, there's no guarentee slider's value double (it saved string!). made it's way interpolatedoubleproperty input parameter , broke variable got added to.

to fix this, needed "sanitize" value field bit multiplying 1.0.

private static native double getslidervalue(string sliderid) /*-{     return $doc.getelementbyid(sliderid).value * 1.0; }-*/; 

this code helped me tracked down type variable @ runtime after compilation, leading me slider.

gwt.log("value: '" + variabletotest + "' type: '" + ((object)variabletotest).getclass().getname() + "'"); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -