我对此很陌生,但是将所有东西都放在我面前,我是这样做的。现在请注意,这是数学上的截断,除了在每行之后的调试中,我不会转换为字符串。
它并不优雅,但似乎有效。这纯粹是一个解决问题的框架。
反正;
import java.util.Scanner;
public class TestConstructs
{
private static double w;
private static int w1;
private static double w2;
private static double w3;
private static int w4;
private static double w5;
private static double w6;
public static void main(String[] args)
{
// TODO Auto-generated method stub
TestConstructs foo = new TestConstructs();
foo.setWage(w);
}
public void setWage(double w)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter Wage: "); //enter something longish like 30987.978654 or w/e
w = input.nextDouble();
w1 = (int)w;
System.out.printf("%d w1\n",w1);
w2 = w - w1;
System.out.printf("%.3f w2\n",w2);
w3 = w2*100;
System.out.printf("%.3f w3\n",w3);
w4 = (int)w3;
System.out.printf("%d w4\n",w4);
w5 = (double)w4;
System.out.printf("%.3f w5\n",w5);
w6 = 0 + w5/100;
System.out.printf("%.3f w6\n",w6);
w = w1 + w6;
System.out.printf("%.3f final value\n",w); //.3 to show zero
input.close();
}
}
我最后得到的输入工资: 30987.978654 30987 w1 0.979 w2 97.865 w3 97 w4 97.000 w5 0.970 w6 30987.970 最终值