RECOMENDATION
Before all and as a recommendation for future questions you might ask, please read:
How to ask.
How to create a Minimal Complete and Verifiable Example (MCVE).
So you can get better help and faster.
SOLUTION 1
You might want to use DecimalFormat
Here's an example on how to use it.
import java.util.*;
import java.text.*;
class NumberConverter {
public static void main(String args[]) {
double number = 12312312312.31;
String pattern = "###.##";
String pattern2 = "###,###.##";
DecimalFormat myFormatter = new DecimalFormat(pattern);
System.out.println(myFormatter.format(number));
myFormatter = new DecimalFormat(pattern2);
System.out.println(myFormatter.format(number));
}
}
All you need to do with this example is replace ,
for .
and viceversa. (I mean separators).
The actual output for my example is:
12312312312.31
12,312,312,312.31
SOLUTION 2
Here's another option on how to achieve it, code taken from @JonSkeet answer. Setting locale, but again assuming your number is a double.
import java.util.*;
import java.text.*;
class NumberConverter {
public static void main(String args[]) {
double number = 13213232132.13;
NumberFormat f = NumberFormat.getInstance(Locale.GERMANY);
((DecimalFormat) f).applyPattern("##0,000.00");
System.out.println(f.format(number));
}
}
SOLUTION 3
If your input is a String
then this could be another way of solving (Since it's a 13 length number that's why I use those limits).
import java.util.*;
import java.text.*;
import java.lang.StringBuilder;
class NumberConverter {
public static void main(String args[]) {
String number = "13.213.232.132,13";
String number1;
String number2;
number1 = number.replace(".", "");
int length;
int length1;
StringBuilder sb = new StringBuilder();
sb.append(number1.charAt(0));
sb.append(number1.charAt(1));
sb.append(".");
int counter = 0;
for(int i = 2; i < 11; i++) {
if(counter == 3) {
sb.append(".");
counter = 0;
}
sb.append(number1.charAt(i));
counter++;
}
sb.append(",");
sb.append(number1.charAt(12));
sb.append(number1.charAt(13));
number2 = sb.toString();
System.out.println(number);
System.out.println(number1);
System.out.println(number2);
}
}
SOLUTION 4
As @kaos said in his comment you can also do it by using DecimalFomatSymbols
in this way:
import java.util.*;
import java.text.*;
import java.lang.StringBuilder;
class NumberConverter {
public static void main(String args[]) {
String formatString = "###,###.##";
double number = 12312312312.31;
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
otherSymbols.setDecimalSeparator(',');
otherSymbols.setGroupingSeparator('.');
DecimalFormat df = new DecimalFormat(formatString, otherSymbols);
System.out.println(df.format(number));
}
}
Hopefuly any of these examples might help you in whatever you're trying to do.
Good Luck