Results 1 to 8 of 8

Thread: [RESOLVED] Insert decimal with dot instead of comma?

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.

  3. #3
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Insert decimal with dot instead of comma?

    Pesumably you are wanting to save German formatted numbers. Are you coding with VB6?
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  4. #4

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    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.

  5. #5
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    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:
    1. using System;
    2. using System.Threading;
    3. using System.Globalization;
    4.  
    5. namespace ConsoleApplication1
    6. {
    7.     class Program
    8.     {
    9.         static void Main(string[] args)
    10.         {
    11.             NumberFormatInfo UKFormat = CultureInfo.CreateSpecificCulture("en-GB").NumberFormat;
    12.             NumberFormatInfo FRFormat = CultureInfo.CreateSpecificCulture("fr-FR").NumberFormat;
    13.             NumberFormatInfo DEFormat = CultureInfo.CreateSpecificCulture("de-DE").NumberFormat;
    14.  
    15.             Test(UKFormat);
    16.             Test(FRFormat);
    17.             Test(DEFormat);
    18.  
    19.             Console.ReadKey();
    20.         }
    21.  
    22.         static void Test(NumberFormatInfo numberFormat)
    23.         {  
    24.             var num1 = "1,234.56";
    25.             var num3 = "1 234,56";
    26.             var num2 = "1.234,56";
    27.  
    28.             TryNumerical(num1,numberFormat);
    29.             TryNumerical(num2,numberFormat);
    30.             TryNumerical(num3,numberFormat);
    31.             Console.WriteLine();
    32.  
    33.         }
    34.  
    35.         static void TryNumerical(string numerical, NumberFormatInfo numberFormat)
    36.         {
    37.             float value = 0;
    38.             Console.WriteLine("{0}\t{1}\t({2})",
    39.                 float.TryParse(numerical,NumberStyles.Any,numberFormat, out value),
    40.                 numerical,
    41.                 value);
    42.         }
    43.     }
    44. }
    Last edited by Milk; Jul 13th, 2011 at 04:50 AM. Reason: better code, grammar
    W o t . S i g

  6. #6

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Insert decimal with dot instead of comma?

    Thank you that was interesting

  7. #7
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: [RESOLVED] Insert decimal with dot instead of comma?

    I reposted better code, it was new to me too
    W o t . S i g

  8. #8

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    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
  •  



Click Here to Expand Forum to Full Width