mercredi 28 mai 2014

Java - direction de numéro décimal dans les Services Web Restful - Stack Overflow


We are developing restful web services for banking operations. The problem is returning decimal numbers. Banking accounts' balance are decimal number and the client of the web service must show this balance in client's localization. So what is the best practice for this problem. Seperation of integer and fractional part is a solution.


For example :



balanceInt: 1500, balanceFrac:85



rather than sending



balance:1500.85.



Any idea?




Simplest solution is to do following


String amt = String.valueOf(1500.85);
String[] strArr = amt.split("\\.");

and return strArr[0] as main amt and str[1] as fraction




Hope you are looking for this. You can get the locale of the client along with webservice request and create a local formatted currency like below. say it is Swedish


double num = 1234.54;
Locale swedish = new Locale("sv", "SE");
NumberFormat swedishFormat = NumberFormat.getCurrencyInstance(swedish);
return swedishFormat.format(num);


We are developing restful web services for banking operations. The problem is returning decimal numbers. Banking accounts' balance are decimal number and the client of the web service must show this balance in client's localization. So what is the best practice for this problem. Seperation of integer and fractional part is a solution.


For example :



balanceInt: 1500, balanceFrac:85



rather than sending



balance:1500.85.



Any idea?



Simplest solution is to do following


String amt = String.valueOf(1500.85);
String[] strArr = amt.split("\\.");

and return strArr[0] as main amt and str[1] as fraction



Hope you are looking for this. You can get the locale of the client along with webservice request and create a local formatted currency like below. say it is Swedish


double num = 1234.54;
Locale swedish = new Locale("sv", "SE");
NumberFormat swedishFormat = NumberFormat.getCurrencyInstance(swedish);
return swedishFormat.format(num);

0 commentaires:

Enregistrer un commentaire