Is it possible to insert a decimal with a dot instead of a comma in a row in mysql (datatype decimal)?
3.14 instead of 3,14
Printable View
Is it possible to insert a decimal with a dot instead of a comma in a row in mysql (datatype decimal)?
3.14 instead of 3,14
Simply format the data upon display/presentation to user. How it is stored in the database (is it 1 byte per 2 digits like in oracle, or is storage to memory of numeric data type comparable to decimals in programming languages) should be irrelevant.
Pesumably you are wanting to save German formatted numbers. Are you coding with VB6?
I am coding in C# and I was scraping a website of a lot of numbers, decimals. But they had a dot instead of a comma so I thought it would be easier to just put it directly in the db without changing anything, but apparently inserting this number:
3.13
Yields 3.
However inserting 3,13 yields 3,13.
I'm not sure if this so much a database question as a 'locale' or 'culture' issue.
You can choose a specific culture...c# Code:
using System; using System.Threading; using System.Globalization; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { NumberFormatInfo UKFormat = CultureInfo.CreateSpecificCulture("en-GB").NumberFormat; NumberFormatInfo FRFormat = CultureInfo.CreateSpecificCulture("fr-FR").NumberFormat; NumberFormatInfo DEFormat = CultureInfo.CreateSpecificCulture("de-DE").NumberFormat; Test(UKFormat); Test(FRFormat); Test(DEFormat); Console.ReadKey(); } static void Test(NumberFormatInfo numberFormat) { var num1 = "1,234.56"; var num3 = "1 234,56"; var num2 = "1.234,56"; TryNumerical(num1,numberFormat); TryNumerical(num2,numberFormat); TryNumerical(num3,numberFormat); Console.WriteLine(); } static void TryNumerical(string numerical, NumberFormatInfo numberFormat) { float value = 0; Console.WriteLine("{0}\t{1}\t({2})", float.TryParse(numerical,NumberStyles.Any,numberFormat, out value), numerical, value); } } }
Thank you that was interesting :)
I reposted better code, it was new to me too :)
oh great, will test that too!