If I do:
float a=5;
System.out.printf("%d", a);
The output of it will be:
5,000000
How do I print 5.000000
? That is, I want to replace the comma by the dot.
If I do:
float a=5;
System.out.printf("%d", a);
The output of it will be:
5,000000
How do I print 5.000000
? That is, I want to replace the comma by the dot.
Maybe this will help you:
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;
public class Teste {
public static NumberFormat seuFormato() {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ROOT);
symbols.setDecimalSeparator(',');
symbols.setGroupingSeparator('.');
return new DecimalFormat("#0.00", symbols);
}
public static void main(String[] args) {
NumberFormat formatter = seuFormato();
float a = 5;
System.out.println(formatter.format(a));
}
}
Retrieved from an example of the Oracle site .
I believe that using replace (), solves your problem an example below:
import java.io.*;
public class Test{
public static void main(String args[]){
String Str = new String("Welcome to Tutorialspoint.com");
System.out.print("Return Value :" );
System.out.println(Str.replace('o', 'T'));
System.out.print("Return Value :" );
System.out.println(Str.replace('l', 'D'));
}
Result:
WelcTme tT TutTrialspTint.cTm
WeDcome to TutoriaDspoint.com