Home ROUND function in mySql giving strange result after using TRUNCATE
Reply: 0

ROUND function in mySql giving strange result after using TRUNCATE

user1008
1#
user1008 Published in May 22, 2018, 4:35 am

I am using a stored procedure in mysql to set the following value to a double variable.

 DECLARE vVar DOUBLE(16,2) DEFAULT 0;

 SET vVar = ROUND(TRUNCATE((29.00 * 1.75/100),2));

Firing the above expression in mySql editor gives 1 (which is correct, since ROUND(0.50) would give 1). However, the value that gets stored in vVar is 0.

On the other hand, if I write

SET vVar = ROUND(TRUNCATE((29.00 * 1.75/100),4));

then the value that gets stored in vVar becomes 1. (which is also correct, since ROUND(0.5075) is 1).

Could someone please explain the strange behavior occurring here.

I had a doubt regarding the datatype of vVar, so I tried changing it from DOUBLE(16,2) to DECIMAL(16,2). But it did not make any difference.

Is there a way to get 1 from the first expression ?

 SET vVar = ROUND(TRUNCATE((29.00 * 1.75/100),2));

Any help would be appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308172 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO