-1

I am building an invoicing system but have come to a bit of a brick wall with decimal fields.

Currently i am using float fields for the totals, tax amount and grand total but i think i should be using decimal fields instead

Can someone shed some light on this for me please to whether I should be using float of decimal fields in my database?

The numbers being stored can be anything from 0.01 to over 10000.00

charlie
  • 415
  • 4
  • 35
  • 83

1 Answers1

0

https://www.tutorialspoint.com/mysql/mysql-data-types.htm

See for a reference guide. I recommend Float as the decimals are defaulted to 2. That should suit your needs. You could also bypass any floating point errors that databases love to throw at you by having a dollars field and a cents field.

Hope that helps.

jacksonecac
  • 284
  • 4
  • 15
  • these are horrible ideas in my not so humble opinion – Drew Nov 29 '16 at 20:56
  • (1) `FLOAT(m,2)` does _two_ roundings, `DECIMAL` avoids such. (2) `FLOAT` has only about 7 significant digits; the OP seems to need about that many. Use `DECIMAL` for monetary data, not `FLOAT`. Never use `(m,n)` on `FLOAT`, it is useless. Switch to `DECIMAL` if you need m or n. – Rick James Nov 29 '16 at 23:59
  • Ouch! I found about 10 errors in that one page from tutorialspoint ! I'm afraid to look at other pages. – Rick James Nov 30 '16 at 00:09