This is still not working. I know that I'm doing something wrong.....?! I would like it always to spit out a long number (no leading zeros) and then my decimal and always two numeric placeholders after the decimal even if there are no pennies in a transaction.
public String formatNumber(double dblNumberIn) throws Exception{
try{
DecimalFormat df1 = new DecimalFormat( "###################.00" ); //Desired format
String strNumberOut = df1.format( dblNumberIn ); //Takes database number and applies the mask above
//should convert a double to ############.## format
return stroutNumber;
}//End Try
catch (Exception e){
System.out.println("formatNumber() function failed within the WriteToFile class. Could not convert double to correct format"
System.out.println(e);
throw e;
}//End Catch
}//End formatNumber method
I'd suggest you writing your customized method otherwise the formatting may not work in every situation.Here is the method I created in my own framework.Hope it helps.
public static String format(double nNumber) {
java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setGroupingUsed(true);
String temp = nf.format(nNumber);
String formatted="";
for (int i = 0; i < temp.length(); i++){
if ( temp.charAt(i) == ',' ) {
formatted += '.';
}else if ( temp.charAt(i) == '.' ) {
formatted += ',';
}else{
formatted += temp.charAt(i);
}
}
return formatted;
}
Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
Hattusas,
In what particular cases would the formatting given by hologram not work? If I pass in a null value? Or extremely large numbers? Just curious. In this case it would be typical for me to run very very large number through this code...100B or perhaps more.
~M
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.