金融记数法 普通数字 相互转换详解编程语言
2023-06-13 09:20:39 时间
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class OlogyCount {
/**
* 金融记数法转换成普通数字型。
* br 例如 132,000,123.00 转换后为 132000123.00
* @param data - 要转换的数字字符串
* @return String - 返回转换后的数字字符串
public static String finalToNormal(String data) {
if(data.trim()==null||data.trim().equals(""))return "";
//String newData = data.replaceAll(",", ""); //since jdk 1.4
String newData = data;
int index = newData.indexOf(,);
while(index != -1){
newData = newData.substring(0, index) + newData.substring(index+1);
index = newData.indexOf(,);
int pos = newData.lastIndexOf(.);
int len = 0; //小数位数
if (pos != -1) {
len = newData.length() - 1 - pos;
try {
double d = Double.parseDouble(newData);
NumberFormat form = NumberFormat.getInstance();
String mask = "###0";
if (len 0) {
mask = "###0.";
for (int i = 0; i len; i++) {
mask = mask + "0";
((DecimalFormat) form).applyPattern(mask);
newData = form.format(d);
} catch (Exception e) {
e.printStackTrace();
return newData;
/**
* 普通数字型转换成金融记数法。
* br 例如 132000123.00 转换后为 132,000,123.00
* @param data - 要转换的数字字符串
* @return String - 返回转换后的数字字符串
public static String normalToFinal(String data) {
if(data.trim()==null||data.trim().equals(""))return "";
int pos = data.lastIndexOf(.);
int len = 0; //小数位数
if (pos != -1) {
len = data.length() - 1 - pos;
try {
double d = Double.parseDouble(data);
NumberFormat form = NumberFormat.getInstance();
String mask = "#,##0";
if (len 0) {
mask = "#,##0.";
for (int i = 0; i len; i++) {
mask = mask + "0";
((DecimalFormat) form).applyPattern(mask);
return form.format(d);
} catch (Exception e) {
e.printStackTrace();
return null;
/**
* 普通数字型转换成金融记数法。
* br 例如 132000123.00 转换后为 132,000,123.00
* br 小数点保留两位
* @param data - 要转换的数字
* @return String - 返回转换后的数字字符串
public static String normalToFinal(double data) {
try {
NumberFormat form = NumberFormat.getInstance();
String mask = "#,##0.00";
((DecimalFormat) form).applyPattern(mask);
return form.format(data);
} catch (Exception e) {
e.printStackTrace();
return null;
/**
* Bean 中普通数字型转换成金融记数法。
* br 小数点保留两位
* @param obj - 要转换的对象
* @param obj - 不要转换的属性集合
* @return String - 返回转换后的数字字符串对象
public static Object beanToNoFinal(Object obj,String jH[]) throws Exception{
Class type = obj.getClass();
boolean flag=false;
try{
//*********获得BEAN 的BEAN信息
BeanInfo info = Introspector.getBeanInfo(type);
//*********通过BEAN的信息获得性质特制集合
PropertyDescriptor[] props = info.getPropertyDescriptors();
//*********循环传递数据
for (int i = 0; i props.length; i++) {
flag=false;
//*********获得第1个BEAN的每个属性名与GET方法
String name = props[i].getName();
Method getMethod = props[i].getReadMethod();
//**********如果获得的属性名是jH含有的属性名 把标志设置为真!
for(int s=0;s jH.length;s++){
if(name.equals(jH[s].toString())||"class".equals(name)
||"multipartRequestHandler".equals(name)||"servlet".equals(name)
||"servletWrapper".equals(name))flag=true;
if(!flag){
//*********获得第BEAN的 SET方法
Method setMethod = props[i].getWriteMethod();
if(getMethod.invoke(obj,null)==null)setMethod.invoke(obj,new Object[]{"0"});
setMethod.invoke(obj,new Object[]{OlogyCount.normalToFinal(Double.valueOf(getMethod.invoke(obj,null).toString()).doubleValue())});
}catch(Exception e){
throw new Exception("获得对象转换科学计算法出错!");
return obj;
/**
* 金融记数法换成普通数字型转。
* br 小数点保留两位
* @param obj - 要转换的对象
* @param obj - 不要转换的属性集合
* @return String - 返回转换后的数字字符串对象
public static Object beanGetNoFinal(Object obj,String jH[]) throws Exception{
Class type = obj.getClass();
boolean flag=false;
try{
//*********获得BEAN 的BEAN信息
BeanInfo info = Introspector.getBeanInfo(type);
//*********通过BEAN的信息获得性质特制集合
PropertyDescriptor[] props = info.getPropertyDescriptors();
//*********循环传递数据
for (int i = 0; i props.length; i++) {
flag=false;
//*********获得第1个BEAN的每个属性名与GET方法
String name = props[i].getName();
Method getMethod = props[i].getReadMethod();
//**********如果获得的属性名是jH含有的属性名 把标志设置为真!
for(int s=0;s jH.length;s++){
if(name.equals(jH[s].toString())||"class".equals(name)
||"multipartRequestHandler".equals(name)||"servlet".equals(name)
||"servletWrapper".equals(name))flag=true;
if(!flag){
//*********获得第BEAN的 SET方法
Method setMethod = props[i].getWriteMethod();
if(getMethod.invoke(obj,null)==null)setMethod.invoke(obj,new Object[]{"0"});
setMethod.invoke(obj,new Object[]{new String(OlogyCount.finalToNormal(getMethod.invoke(obj,null).toString().trim()))});
}catch(Exception e){
throw new Exception("获得对象科学计算法转换数字出错!");
return obj;
/**
* Bean 中普通数字型转换成金融记数法。
* br 小数点保留两位
* @param obj - 要转换的对象
* @param obj - 要转换的属性集合
* @return String - 返回转换后的数字字符串对象
public static Object beanToFinal(Object obj,String jH[]) throws Exception{
Class type = obj.getClass();
boolean flag=false;
try{
//*********获得BEAN 的BEAN信息
BeanInfo info = Introspector.getBeanInfo(type);
//*********通过BEAN的信息获得性质特制集合
PropertyDescriptor[] props = info.getPropertyDescriptors();
//*********循环传递数据
for (int i = 0; i props.length; i++) {
flag=false;
//*********获得第1个BEAN的每个属性名与GET方法
String name = props[i].getName();
Method getMethod = props[i].getReadMethod();
//**********如果获得的属性名是jH含有的属性名 把标志设置为真!
for(int s=0;s jH.length;s++){
if(name.equals(jH[s].toString()) !"class".equals(name)
!"multipartRequestHandler".equals(name) !"servlet".equals(name)
!"servletWrapper".equals(name))flag=true;
if(flag){
//*********获得第BEAN的 SET方法
Method setMethod = props[i].getWriteMethod();
if(getMethod.invoke(obj,null)==null)setMethod.invoke(obj,new Object[]{"0"});
setMethod.invoke(obj,new Object[]{OlogyCount.normalToFinal(Double.valueOf(getMethod.invoke(obj,null).toString()).doubleValue())});
//System.out.println(name+"---"+getMethod.invoke(obj,null).toString());
}catch(Exception e){
throw new Exception("获得对象转换科学计算法出错!");
return obj;
/**
* 金融记数法换成普通数字型转。
* br 小数点保留两位
* @param obj - 要转换的对象
* @param obj - 要转换的属性集合
* @return String - 返回转换后的数字字符串对象
public static Object beanGetFinal(Object obj,String jH[]) throws Exception{
Class type = obj.getClass();
boolean flag=false;
String name="";
Method getMethod=null;
try{
//*********获得BEAN 的BEAN信息
BeanInfo info = Introspector.getBeanInfo(type);
//*********通过BEAN的信息获得性质特制集合
PropertyDescriptor[] props = info.getPropertyDescriptors();
//*********循环传递数据
for (int i = 0; i props.length; i++) {
flag=false;
//*********获得第1个BEAN的每个属性名与GET方法
name = props[i].getName();
getMethod = props[i].getReadMethod();
//**********如果获得的属性名是jH含有的属性名 把标志设置为真!
System.out.println(name);
for(int s=0;s jH.length;s++){
if(name.equals(jH[s].toString()) !"class".equals(name)
!"multipartRequestHandler".equals(name) !"servlet".equals(name)
!"servletWrapper".equals(name))flag=true;
if(flag){
//*********获得第BEAN的 SET方法
Method setMethod = props[i].getWriteMethod();
if(getMethod.invoke(obj,null)==null)setMethod.invoke(obj,new Object[]{"0"});
if(Double.valueOf(getMethod.invoke(obj,null).toString()).doubleValue()!=new Double("0").doubleValue())
setMethod.invoke(obj,new Object[]{new String(OlogyCount.finalToNormal(getMethod.invoke(obj,null).toString().trim()))});
}catch(Exception e){
try {
System.out.println(e+e.getMessage()+name+getMethod.invoke(obj,null).toString());
} catch (IllegalArgumentException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} catch (InvocationTargetException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
throw new Exception("获得对象科学计算法转换数字出错!");
return obj;
}
13356.html
cjava相关文章
- struts2:JSON在struts中的应用(JSP页面中将对象转换为JSON字符串提交、JSP页面中获取后台Response返回的JSON对象)详解编程语言
- spring mvc 日期转换详解编程语言
- python生成验证码,文字转换为图片详解编程语言
- 公历农历互相转换的Java日历工具类详解编程语言
- 字符串 java字符串编码转换处理类详解编程语言
- java中数字与ASCII码的相互转换的代码详解编程语言
- [javaSE] 进制转换(二进制十进制十六进制八进制)详解编程语言
- Java中Date日期字符串格式的各种转换详解编程语言
- List与Json的相互转换详解编程语言
- 在java中数据类型long类型如何转换为int类型详解编程语言
- Jackson 框架JSON、XML、List、Map直接相互转换详解编程语言
- Json,String,Map之间的转换详解编程语言
- Python时间,日期,时间戳之间转换,时间转换时间戳,Python时间戳转换时间,Python时间转换时间戳详解编程语言
- 变量 转换详解编程语言
- MySQL转换为时间戳的技术指南(mysql转为时间戳)
- abap指针分配显性强制转换详解编程语言
- ABAP-JSON格式转换详解编程语言
- js字符串和数字对象互相转换详解编程语言
- 利用jsoncpp将json字符串转换为Vector详解编程语言
- LeetCode 0109 有序链表转换二叉搜索树详解编程语言
- JSON 字符串 与 java 对象的转换详解编程语言
- ABAP – 日期格式转换 & ABAP常用日期处理函数详解编程语言