百分比
来源:互联网 发布:办公室软件培训班 编辑:程序博客网 时间:2024/06/12 00:24
获取百分比的方法:
package com.haizhu;import java.text.DecimalFormat;import java.text.NumberFormat;public class GetPercent {static String getPercent1(int a,int t){ double da = a * 1.0; double dt = t * 1.0; double per = da/dt; DecimalFormat df1 = new DecimalFormat("##.00%"); // ##.00% return df1.format(per);}/*****************************************************************************************************/static String getPercent2(int a,int t){ float da = a * 1.0f; float dt = t * 1.0f; float per = da/dt; NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(2); percentFormat.setMinimumFractionDigits(2); return percentFormat.format(per);}static String getPercent2All(int a,int t){ float da = a * 1.0f; float dt = t * 1.0f; float per = da/dt; NumberFormat percentFormat = NumberFormat.getPercentInstance(); //最大整数位数,最大为两位,如果设置为1位,“29%” 就会显示为 “9%” percentFormat.setMaximumIntegerDigits(2); //最小整数位数, percentFormat.setMinimumIntegerDigits(2); percentFormat.setMaximumFractionDigits(2);//最大小数位数 percentFormat.setMinimumFractionDigits(2);//最小小数位数 return percentFormat.format(per);//自动转换成百分比显示.. }/*****************************************************************************************************/public static void main(String[] args) {String str1 = getPercent1(23,45);System.out.println(str1);String str2 = getPercent2(1,2000);System.out.println(str2);}}结果:
51.11%0.05%
- 百分比
- 百分比
- 百分比
- 百分比
- 百分比
- 百分比进度条
- 计算百分比
- java 百分比
- 统计百分比
- java 百分比
- 圆弧百分比
- 圆环百分比
- 百分比布局
- 百分比布局
- 百分比布局
- margin百分比
- 百分比布局
- 百分比布局
- php获取ip地址
- Mysql命令
- 【每周一译】如何为你即将搭建的hadoop集群选择硬件
- Ubuntu如何完全删除JDK及重新安装
- iOS 5 故事板入门(3)
- 百分比
- 各种排序
- hdu 4707 Pet 水
- Java之软引用、弱引用、虚引用
- 二维码技术
- Dojo 的订阅/发布模式
- Android中帧动画在Activity启动时自动运行的几种方式
- 求随机数构成的数组中找到长度大于=3的最长的等差数列
- 【UG活动ppt】敏捷项目管理经验分享