|
-
Jul 12th, 2011, 06:47 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Insert decimal with dot instead of comma?
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
-
Jul 12th, 2011, 07:27 PM
#2
Re: Insert decimal with dot instead of comma?
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.
-
Jul 13th, 2011, 02:41 AM
#3
Frenzied Member
Re: Insert decimal with dot instead of comma?
Pesumably you are wanting to save German formatted numbers. Are you coding with VB6?
-
Jul 13th, 2011, 03:49 AM
#4
Thread Starter
Hyperactive Member
Re: Insert decimal with dot instead of comma?
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.
-
Jul 13th, 2011, 04:37 AM
#5
Re: Insert decimal with dot instead of comma?
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); } } }
Last edited by Milk; Jul 13th, 2011 at 04:50 AM.
Reason: better code, grammar
W o t . S i g
-
Jul 13th, 2011, 04:48 AM
#6
Thread Starter
Hyperactive Member
Re: Insert decimal with dot instead of comma?
Thank you that was interesting
-
Jul 13th, 2011, 04:52 AM
#7
Re: [RESOLVED] Insert decimal with dot instead of comma?
I reposted better code, it was new to me too
-
Jul 13th, 2011, 04:54 AM
#8
Thread Starter
Hyperactive Member
Re: [RESOLVED] Insert decimal with dot instead of comma?
oh great, will test that too!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|