Java: Format double with decimals
问题 In Objective C I have been using this code to format a value so that a value with zero decimals will be written without decimals and a value with decimals will be written with one decimal: CGFloat value = 1.5; return [NSString stringWithFormat:@"%.*f",(value != floor(value)),value]; //If value == 1.5 the output will be 1.5 //If value == 1.0 the output will be 1 I need to do the same thing for a double value in Java, I tried the following but that is not working: return String.format("%.*f",