Valor con decimal en un valor
Consulta, Comunidad:
Existe alguna forma de de cambiar el punto por una coma decimal, sin hacer uso del replace de la clase String?
Ejemplo
El valor es un Double, pero hacen uso de la clase String para hacer el cambio Str.replace(".",",");
- Inicie sesión o regístrese para enviar comentarios
Cambiando la localidad
Con DecimalFormat o NumberFormat checa aquí
import java.text.NumberFormat;
class Example
{
public static void main (String[] args) throws java.lang.Exception
{
String pattern = "####.####";
Locale locale = new Locale("da", "DK");
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale);
decimalFormat.applyPattern(pattern);
System.out.println(decimalFormat.format(43213.45323421));
}
}
Tambien
import java.text.DecimalFormatSymbols;
class Example
{
public static void main (String[] args) throws java.lang.Exception
{
String pattern = "####.####";
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
otherSymbols.setDecimalSeparator(',');
otherSymbols.setGroupingSeparator('.');
DecimalFormat decimalFormat = new DecimalFormat(pattern, otherSymbols);
decimalFormat.applyPattern(pattern);
System.out.println(decimalFormat.format(43213.45323421));
}
}