Har*_*lva 3 java percentage long-integer
考虑这种情况.
我有2个长变量a和b.
我正试图获得这些格式的百分比:
xx.x和0.xx.
我已经尝试过将两者分别加倍和分割,但我没有采用后一种格式.
那样的东西?
long a = 12, d = 34;
double ratio = a / (double) d;
DecimalFormat ratioFormat = new DecimalFormat("#.##");
DecimalFormat percentFormat= new DecimalFormat("#.#%");
System.out.println("ratio = " + ratioFormat.format(ratio));
System.out.println("percent = " + percentFormat.format(ratio));
Run Code Online (Sandbox Code Playgroud)
哪个输出:
ratio = 0.35
percent = 35.3%
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4050 次 |
| 最近记录: |