我花了一段时间试图弄清楚为什么它不会在我的 java 代码中使用十进制格式。我已经用其他整数声明了十进制格式,但仍然出现错误。这是我的代码:
public class Assign31
{
public static void main(String [] args)
{
DecimalFormat speedPattern = new DecimalFormat( "00.00" );
int gearRadius = 100;
double pi = Math.PI;
int cadence = 90;
double gearspeed = gearRadius * pi;
double speedmph = gearspeed % cadence;
System.out.println("The speed of the cyclist on a bike with gear 100.0 and cadence 90 is " +
speedmph + " mph.");
System.out.println("The speed (rounded) of the cycleist on the bike with gear 100.0 and cadence 90 is " +
speedPattern.format(speedmph));
}
}