Solved

Decimal Seperator Problem

Posted on 2004-10-09
8
774 Views
Last Modified: 2008-01-16
Hi... I have a problem with the decimal seperator in mysql while I am trying to insert or update data which has atleast 2 decimal places.
In Turkey, defoult currency format is like that 123,456.98 .... But in europe the default currency format is like that 123.345,65 ... So whenever I try to insert 34,12 I only see the 34.00. Nothing more... My field type is Double(10,2). I am able to insert 34.12 If I am using Mysql Control Center directly from sql query. Is it possible change the defoult mysql locale setting which is suitable to Turkish type?
0
Comment
Question by:blacklord
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Expert Comment

by:jdlambert1
Comment Utility
For complete accuracy with monetary values, you should use the Decimal datatype, and you should use your front-end to control the formatting to and from European standards.

DECIMAL( length , decimals ) [UNSIGNED] [ZEROFILL]

From http://dev.mysql.com/doc/mysql/en/Choosing_types.html:

Accurate representation of monetary values is a common problem. In MySQL, you should use the DECIMAL type. This is stored as a string, so no loss of accuracy should occur. (Calculations on DECIMAL values may still be done using double-precision operations, however.) If accuracy is not too important, the DOUBLE type may also be good enough.
0
 

Author Comment

by:blacklord
Comment Utility
Thanks for the answer.. But It still accept 12.45 rather than 12,45. This is the problem that I am trying to solve. My db should accept , as decimal seperator.
0
 
LVL 7

Expert Comment

by:petoskey-001
Comment Utility
MySql will not accept decimal as seperator.  I'm afraid you'll have to do the conversion on your front end.  Their is no currency type as in MSSQL, Oracle, PostgreSql or even MS Access.  Comma's are viewed as the field seperator in mysql and that's about it.

Your choices are convert on the front end to decimal, or do some programming on the MySql backend for a custom User Defined Function (search mysql udf) to convert a currency string to a decimal number.  You would have to wrap all "money" fields with a euro_to_decimal('12,45') and then use decimal_to_euro(12.45) to get it back.

As useful as it sounds, I see know of no such utility that exists right now.  Here is a list of UDF.
http://empyrean.lib.ndsu.nodak.edu/~nem/mysql/udf/

Even MySql v5 in development has no plans posted to add a money data type.


Possibly we can help with the front end issue, what are you working in?
0
 

Author Comment

by:blacklord
Comment Utility
Thanks for the answer petoskey-001. I understand your point. The important point is not to store decimal numbers with ",". Later then when I use Crytal report, that reporting program generates much more problems because of my table field type.

"Your choices are convert on the front end to decimal, or do some programming on the MySql backend for a custom User Defined Function (search mysql udf) to convert a currency string to a decimal number.  You would have to wrap all "money" fields with a euro_to_decimal('12,45') and then use decimal_to_euro(12.45) to get it back."

Can you give me some example about it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Accepted Solution

by:
petoskey-001 earned 250 total points
Comment Utility
Well here's a FAQ
http://empyrean.lib.ndsu.nodak.edu/~nem/mysql/udf/faq.html

Here's a source forge project to download source code
http://mysql-udf.sourceforge.net/

And of course the official manual on the subject...
http://dev.mysql.com/doc/mysql/en/Adding_functions.html


0
 

Author Comment

by:blacklord
Comment Utility
Thanks for your help petoskey...
0
 

Expert Comment

by:erkansaldir
Comment Utility

you can use string  for update,calculate,insert money(123,456.98 )  format and you can modify your Currency using replace and cast function.
Example :
SELECT  sum(CAST((replace(carihareket.tutar,',','.')*100) as signed)/100) FROM carihareket  where Sirano=4

1-Replace , to .
2-convert currency to signed value using CAST function
3- convert signed value  to float using *100 and  / 100
4- Sum of column
 
0
 

Expert Comment

by:erkansaldir
Comment Utility
And  i find  second way,
1-Create your money column double(14,2)  
2-And use :  Replace(Format(sayi.ValueDouble, "###0.00"), ",", ".")   during using  insert and  update query.
___________________________________________________________________________________
example Update::
updateCmd = "UPDATE aidatcarihareket SET tutar='" & Replace(Format(sayi.ValueDouble, "###0.00"), ",", ".") & "' WHERE SiraNo = 1" ' ,update_by='" & adminNo & "' , update_date='" + yaratilmatarihi.ToString("yyyyMMddhhmmss") + "' WHERE SiraNo = '" & SiraNo & "'"

if You use my second way you   dont need any format and string  operation when you want to use select . :)
___________________________________________________________________________________
Example Select ::
  updateCmd = "select tutar from aidatcarihareket WHERE SiraNo = 1" ' ,update_by='" & adminNo & "' , update_date='" + yaratilmatarihi.ToString("yyyyMMddhhmmss") + "' WHERE SiraNo = '" & SiraNo & "'"

            Dim myCommand As New OdbcCommand(updateCmd, myConnection)
            myConnection.Open()
            Dim deger As Double
            deger = myCommand.ExecuteScalar()

==========================================================
Erkan SALDIR 16 - January 2005
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now