Fork me on GitHub

CSS+DIV进度条

<style type="text/css">
.Bar { position: relative; width: 200px;    /* 宽度 */ border: 1px solid #B1D632; padding: 1px; }
.Bar div { display: block; position: relative; background:#00F;/* 进度条背景颜色 */ color: #333333; 
      height
: 20px; /* 高度 */ line-height: 20px; /* 必须和高度一致,文本才能垂直居中 */ } .Bar div span{ position: absolute; width: 200px; /* 宽度 */ text-align: center; font-weight: bold; } </style>
<div class="Bar">
    <div style="width: 50%;">
        <span>50%</span>
    </div>
</div>
  //此方法用于计算百分比
  public String getPercent(int x,int total){ if(x==0&&total!=0){ return "0"; }else if(x==0&&total==0){ return "100%"; } String result="";//接受百分比的值 double x_double=x*1.0; double tempresult=x_double/total; //保留到小数点后几位 DecimalFormat df = new DecimalFormat("0.00%"); //##.00% 百分比格式,后面不足2位的用0补齐 result= df.format(tempresult); //注释掉的也是一种方法 //NumberFormat nf = NumberFormat.getPercentInstance(); //nf.setMinimumFractionDigits( 2 ); //result=nf.format(tempresult);      return result; }
posted @ 2015-03-22 15:36  何海洋  阅读(1116)  评论(0编辑  收藏  举报