Open LucasBrazi06 opened 1 year ago
The Java code:
import java.math.*;
public class Main {
public static void main(String[] args) {
double maxCurrentPerPhase = 67.124;
int sumUsedPhases = 3;
double expectedResult = 201.372;
// Without Big Decimal
System.out.println("Without BigDecimal");
double result1 = maxCurrentPerPhase * sumUsedPhases;
System.out.println("26.4 * 3 = " + result1);
System.out.println("Equals to expected result = " + (result1 == expectedResult));
// With Big Decimal
System.out.println("With BigDecimal");
double result2 = new BigDecimal(maxCurrentPerPhase).multiply(new BigDecimal(sumUsedPhases), new MathContext(16)).doubleValue();
System.out.println("26.4 * 3 = " + result2);
System.out.println("Equals to expected result = " + (result2 == expectedResult));
}
}
Error 400 in calling the Smart Charging java web service:![image](https://user-images.githubusercontent.com/25266945/227782016-5c191ab7-cc7a-4939-9339-01d3b46d0fcb.png)
3 x 67.124 = 201.372 so the Smart Charging service should not throw an exception!
In JS you can reproduce the error that may occur in Java:
Actions: -> Smart Charging Java has to be fixed -> All operation in Smart Charging integration in NodeJs has to use Decimal.Js or round to integer all the values -> Unit tests have to be adjusted accordingly