Division on MySQL

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Division on MySQL



Please help me. I have division problem on mysql. I have query like this :



SELECT (8/10) as res



This query result is 0.8000 and I want the result is 0.8 not 0.8000.
Does someone have a solution?





80/10 = 8.0000?
– P.Salmon
Aug 10 at 7:51





Possible duplicate of Format number to 2 decimal places
– juzraai
Aug 10 at 7:51





SELECT (80/10) as res this query results in 8.0000 and SELECT (80/100) as res results in 0.8000 and SELECT ROUND((80/100), 1) as res results in 0.8
– codtex
Aug 10 at 7:51


SELECT (80/10) as res


8.0000


SELECT (80/100) as res


0.8000


SELECT ROUND((80/100), 1) as res


0.8





@codtex how with 15/100 ? it will result 0.2. i wanna remove 0 after 8, so the result is 0.8 or with case 15/100, the result is 0.15 not 0.1500
– Al-kadafi
Aug 10 at 8:14




2 Answers
2



EDIT :Trim with add 0 value


SELECT TRIM((80/100))+0





is it wrong answer ? why isnot useful ?
– Yogi Prayoga
Aug 10 at 8:13





how with 15/100 ? it will result 0.2. i wanna remove 0 after 8, so the result is 0.8 or with case 15/100, the result is 0.15 not 0.1500
– Al-kadafi
Aug 10 at 8:18





you question are not clear.. You can use trim with add 0 like this SELECT TRIM((80/100))+0
– Yogi Prayoga
Aug 10 at 8:55





oke thanks, sorry. that's solve for division problem. but i wanna ask, how about subtraction, i get result 0.6000000000001 of ((80/100)*1)-0.2 operation, i get value 80,100,1, 0.2 from query too. what's the problem?
– Al-kadafi
Aug 10 at 9:23





owh..may you try with this query; SELECT TRIM(((80/100)*1)-0.2)+0 ... it will give you result 0.6
– Yogi Prayoga
Aug 10 at 10:34



You are not very clear but I think the following queries does what you want:


SELECT TRIM(TRAILING '0' FROM ( 80/100 )) as res;
# Output is 0.8

SELECT TRIM(TRAILING '0' FROM ( 15/100 )) as res;
# Output is 0.15



It will remove the trailing 0 from the result.



If you do for example:


SELECT TRIM(TRAILING '0' FROM ( 81/11 )) as res;
# Output is 7.3636



So the question is what exactly do you want to do? Do you need rounding at all?





thanks @codtex, i will try it. actually, i have a long query for get value of transaction, even if my query is split, this is only a calculation of ((80/100) * 1) - 0.2. and the result isn't 0.6 but 0.6000000000000001. i think division is the problem, so i ask like that.
– Al-kadafi
Aug 10 at 8:31







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard