7

How can you make mysql understand non-English decimal points in integer/float fields?

setLocale(LC_ALL, 'da_DK.ISO-8859-1');

eg:

0,25 will be inserted as 0
0.25 will be inserted as 0.25
gbn
  • 422,506
  • 82
  • 585
  • 676
clarkk
  • 27,151
  • 72
  • 200
  • 340

4 Answers4

15

One of the reasons you can't do that is that the comma , is used for separating field-values in INSERT statements.

INSERT INTO a(b,c) VALUES (3,4,5) would be ambiguous.

Should it result into b=3.4 , c=5 or b=3 , c=4.5 ?

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
  • good answer. I'll never understand WHO designated the painful comma as a separator of things when there are at least [4 separators in ASCII](https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text) – Ivan Ferrer Villa Oct 14 '16 at 12:05
  • @IvanFerrerVilla those are non printable characters, aimed to be used in files. SQL is a language that is to be readable. – ypercubeᵀᴹ Oct 14 '16 at 12:10
  • yes, but from the beginnings of computer ages they could have invented a printable/viewable separator char instead of using the ordinary comma. And add a key to the standard keyboard to write it. We use commas everywhere in our languaje! :) – Ivan Ferrer Villa Oct 14 '16 at 14:32
3

Numbers aren't affected by locale settings (same in SQL Server too).

So you'd have to send as "0.25"

gbn
  • 422,506
  • 82
  • 585
  • 676
0

The easiest way I would think would be to use a wrapper for your mysql object that will set the locale to en_US.utf8 before your query and after the query puts it back to da_DK.ISO-8859-1.

It looks like this does the opposite of what you're looking for.

Mike
  • 23,542
  • 14
  • 76
  • 87
-4

You might want to try something like REPLACE('3,1415926', ',' , '.' )

Vijay
  • 1
  • 1
  • This would only work if you have _exactly_ `3,1415926` as a string somewhere and would have to perform this for _every_ occurrence you wish to change. Hardly useful in my opinion. – Werner Dec 13 '13 at 14:53
  • 1
    This is not a solutions of asked question. please read question again carefully – Umar Abbas Sep 18 '15 at 10:57