`
jh_soft
  • 浏览: 14557 次
  • 性别: Icon_minigender_2
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论
阅读更多
private static String RMB = "¥";
public String getValueByPosition(BigDecimal money,int position){
money = formEntity.getPayMoney();
String target = money.toString();
int length = target.length();
int index = length - 1 - position;

if(position == length - 1){
return RMB;
}
if(position > length) {
return "";
}

if(position < length - 1) {
String result = "";
//小数点保留两位,所以当你的取值索引大于等于2时,你必须将小数点去掉
//因为你取值的顺序其实是从右到左的,所以索引位置应该是-1,
//为什么-1? 小数点占一位. 所以数值是1
//为什么是减? 从右到左取值的,subString方法其实是从左到右开始计算的 也就是说第一位是0,1,2,...,length -1;
//截取最后一位的方法就是substring(字符串长度-1)或substring(字符串长度-2,字符串长度-1);
//因为我们是从右到左开始取值的 我们声明了一个变量int index = length -1 -position;
//string result = target.substring(index,index+1);
if(position >= 2) {
result = target.substring(index-1,index);
} else {
result = target.substring(index,index+1);
}
return result;
}
return "";
}
getValueByPosition(payMoney,10)getValueByPosition(payMoney,9)
getValueByPosition(payMoney,8)getValueByPosition(payMoney,7)
getValueByPosition(payMoney,6)getValueByPosition(payMoney,5)
getValueByPosition(payMoney,4)getValueByPosition(payMoney,3)
getValueByPosition(payMoney,2)getValueByPosition(payMoney,1)
getValueByPosition(payMoney,0)
显示结果
亿万千百十万千百十个
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics