I'm trying to add two values together e.g. 14.0 + 2.1 = 16.1 but I keep on getting them added onto each other e.g 14.0 + 2.1 = 14.02.1
var miledistance = miledistance1 + miledistance2;
I'm trying to add two values together e.g. 14.0 + 2.1 = 16.1 but I keep on getting them added onto each other e.g 14.0 + 2.1 = 14.02.1
var miledistance = miledistance1 + miledistance2;
For Java:
Make sure they are both float values.
Try casting:
miledistance = (float) miledistance1 + (float) miledistance2;
Or use Float.valueOf():
miledistance = Float.valueOf(miledistance1) + Float.valueOf(miledistance2);
For Javascript:
miledistance = parseFloat(miledistance1) + parseFloat(miledistance2);
NOTE: Java and javascript are not the same language.
Float.valueOf(...) instead of the cast)?