Problem with Float and SQL

Hi Guys and Girls,
I’am Facing a little(big) problem right now.
Ok i got a Database with some floats rows
The problem is from unity i can’t save my floats into a float row from my DB beacause unity store my float with a comma separator instead of a dot separator ( when i type 2.225f it appears on screen as 2,225)

I search for so many ideas, like save it as a string but i need to do some maths on this number after i get it from the DB

I saw some things about CultureInfo but i can’t go through it because i can’t found enough informations about

I work with Unity 2017.3.1f1
I am in France so my CultureInfo is fr-Fr by default.

Can anyone help me pls ???

The way you phrased your question it’s not clear what exactly doesn’t work. Where does the value come from and what doesn’t work? Having the value as float in Unity and then transfer it into a database? Or the other way round? In the first case it highly depends on how you actually store it in the database from Unity. Usually when using a web interface (like PHP) you have to go through a string conversion anyways. The same is true when you actually use an SQL statement like insert or update as SQL is a text based language.

You can simply force the invariant culture by doing this:

string str = someFloat.ToString(CultureInfo.InvariantCulture);

This will convert the float value always the same way, regardless of the local culture. Actually in germany we also have the comma as decimal point, though i’ve changed the decimal point in my culture settings of my OS years ago ^^.

Likewise when you want to parse a string into a float you would use

public static float ParseFloat(string aStr, float aDefault = 0f)
{
    float v;
    if (float.TryParse(aStr, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
        return v;
    return aDefault;
}

Thank you for the answer, I have a float called TIME which is a lap time (race car game), his format is “00,000”
I try to store it from unity editor in C# using the UPDATE command.

By the way i’ll try asap the invariant culture i hope it works, and… can you tell me quickly how to change it for my OS too ?

Thanks,
Johann!