I am attempting to create a function that will output a Double as a String with the following requirements:
- It will not show with exponents. I believe Double.toString(dblVal) or dblVal.toString() will take care of the exponent issue.
- If the Double is null it will not error and will display as 'null'. I believe String.valueOf(dblVal) will take care of this automatically if the Double is null.
Here is what I have:
function doubleToString(Double dbl) {
String strVal = null;
if (dbl != null)
strVal = String.valueOf(dbl);
return strVal;
}
What would be the best way to achieve both requirements? I don't think String.valueOf will get rid of the exponent so should I not be using String.valueOf() and instead using dblVal.toString() and then just to a manual check before hand on whether it is null or not and if so make strVal null?