* [EMAIL PROTECTED]
> Hello,
> I have a table bill like
> when (date), how_much (float), what (varchar).
>
> Now I store some bills on it - how_much will get numbers with 2 digits
> after point.

Why do you think that? Note that FLOAT is an approximate numeric type. The
value you insert is stored in a binary format, and when you retrieve it, it
may have a slightly different value from what you inserted, like you have
observed.

Read more here:

<URL: http://www.mysql.com/doc/en/Problems_with_float.html >
<URL: http://www.mysql.com/doc/en/Numeric_types.html >

> Then I want to know how much money I spent each month.
> SELECT SUM(how_much), YEAR(when), MONTH(when) FROM bill GROUP BY
> (YEAR(when)*12+MONTH(when))

I don't understand this GROUP BY clause... the subject of this message
indicates that this too was an issue? I would have expected "GROUP BY
YEAR(when), MONTH(when)".

> I expect to get numbers with not more than 2 digits after the point.
> Surprisingly I get ??.259999978 when I expect to get ??.26 or some else
> strange numbers.

See the ROUND() function:

<URL: http://www.mysql.com/doc/en/Mathematical_functions.html#IDX1291 >

Note the C library dependency of this function, it may behave differently on
different computers.

I would store the how_much as pfennnigs or cents or whatever and use an
INTEGER type.

--
Roger


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to