Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Decimal formats in MySQL

Posted on 2004-09-13
6
Medium Priority
?
2,084 Views
Last Modified: 2008-03-10
Hi all

How do i define a currency format in mySql
I have imported a Access database table to mySql

Got a collum containing prices  with 2 decimal after a comma... like this    7,25  euro
but after the import / conversion   i only get                                            7      euro  in the table  

i made a dump file where i clipped this behavior

`Pris` DECIMAL DEFAULT 0,

So is it possible to define the above pice of code to containe 2 decimals after the comma

thanks in advance

rgds Jens
0
Comment
Question by:vbturbo
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:itcnbwise
ID: 12045040
Define your field in MySQL as this:

DECIMAL( 3, 2 )

This will allow 3 digits to the right of the decimal and 2 to left, as such:

999.99

If you want more digits (meaning mo money), increase the 3.
0
 
LVL 4

Accepted Solution

by:
itcnbwise earned 300 total points
ID: 12045081
Sorry - my bad.  From the MySQL manual:

salary DECIMAL(5,2)

In this example, 5 is the precision and 2 is the scale. The precision represents the number of significant decimal digits that will be stored for values, and the scale represents the number of digits that will be stored following the decimal point.

In this case, a 5 on the right means you will have 4 digits to the right of decimal, so this wil allow:

9999.99

My above example, DECIMAL( 3, 2 ), would only allow this:

99.99

Hope this helps!


0
 
LVL 18

Author Comment

by:vbturbo
ID: 12045249
Hi there

I got only 2more questions

1) ...for example  if i want to define the digits before the comma
as a wildcard/joker sign  (*,2) is that posible ?

2)  and is it also posible for the amount of digits to grow ???

I want do it  something like this....because if want to make a sale than i cant know the amout
of digits (price)  in advance

jens
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 4

Expert Comment

by:itcnbwise
ID: 12045876
I'm afraid you can't wildcard.  But you can declare it as large as you want, like 10, 2, to accomodate $999,999,999.99.  And If you're selling something that costs that much, you can afford to pay someone else to program it :)
0
 
LVL 4

Expert Comment

by:itcnbwise
ID: 12045885
Sorry, in answer to your second question: since you can't wildcard, the digits can't grow.  You have to explicitly declare them.
0
 
LVL 18

Author Comment

by:vbturbo
ID: 12047993
Hi Again

Want to thank you for simple and easy explanation

Regards Jens
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

886 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