Replace “.” by “,” in float column and BigDecimal column

I want to replace “.” by “,” in a Float Column .

Here is my code .

I’m i missing something in the conversion Part ?

public static Float    replace_float(Float  x) {

    if ( x!=null && !"".trim().equals(x) ) {
        
        return   Float.parseFloat(String.valueOf(x).replace(".", ","))  ; 
    }
   
    return   Float.parseFloat(String.valueOf(x).replace(".", ","))  ; 
}

Answer

Your question is about the output format of a float. Because only when your float is to be displayed is it converted into a string and, depending on the language settings on the computer, it is output with a point or a comma. If you want to change that, you do not have to change anything on the Float, you only have to format it accordingly during the output.

For example, you could use the German number format to display your Float with a comma.

public String commaFloat(Float yourValue){
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
    nf.setGroupingUsed(false);
    return nf.format(yourValue);
}

I hope you find the answer helpful.