There is a good question on rounding decimals in Java here. But I was wondering how can I include the trailing zeros to display prices in my program like: $1.50, $1.00
T
public static String getFormattedData(String actualString)
{
String subString = "0.0";
if(actualString.contains("."))
{
subString = actualString.substring(actualString.indexOf("."), actualString.trim().length());
if(Double.parseDouble(subString) > 0.0)
return actualString;
else
actualString = actualString.substring(0, actualString.indexOf("."));
}
return actualString;
}