Re: MySQL function parameter types

From: Luuk <luuk_at_invalid.lan>
Date: Sat, 29 Aug 2015 21:33:16 +0200
Message-ID: <55e208fc$0$23805$e4fe514c_at_news.xs4all.nl>


On 29-08-15 20:02, Stefan Ram wrote:
> Luuk <luuk_at_invalid.lan> writes:
>> it says:
>> FORMAT(X,D)
>> Formats the number X to a format like '#,###,###.##', rounded to D
>> decimal places, and returns the result as a string. If D is 0, the
>> result has no decimal point or fractional part.
>> what official explanation are you looking for, when just looking at this
>> one function?
>
> One can observe that X above has more precision than DOUBLE:
>
> SELECT FORMAT( 1.000000000000000000000000000001, 33 );
>
> +------------------------------------------------+
> | FORMAT( 1.000000000000000000000000000001, 33 ) |
> +------------------------------------------------+
> | 1.000000000000000000000000000001 |
> +------------------------------------------------+
>
> So, X does not narrow the decimal value to DOUBLE.
> X has a DECIMAL or a VARCHAR type.
>

but this:

SELECT FORMAT( 1.000000000000000000000000000001, 33 ) = 
1.000000000000000000000000000001 ;;

also returns: '1' as a result.

What about rounding here?

it's a string (the result of 'FORMAT') compare to someting else....

When doing this:

create table T1 as SELECT FORMAT( 1.000000000000000000000000000001, 33 ) 
, 1.000000000000000000000000000001 ;

show create table T1;

CREATE TABLE `T1` (

`FORMAT( 1.000000000000000000000000000001, 33 )` varchar(77) DEFAULT NULL,
`1.000000000000000000000000000001` decimal(31,30) NOT NULL DEFAULT 
'0.000000000000000000000000000000'

) ENGINE=InnoDB DEFAULT CHARSET=utf8

You can see that this second expression is treated as a DECIMAL(..), and not as a DOUBLE

> Now the programmer can learn from this that high-scale
> decimal values will be rounded to double, when passed
> to EXP, but not when passed to format, where they will
> be preserved.
>

I think a programmer has muc more important stuff to think about ;)

> Maybe, »open source« software also means: »We do not
> have to be too precise in the manual, as one can always
> look it up in the source code« ...

i do not understand .... Received on Sat Aug 29 2015 - 21:33:16 CEST

Original text of this message