MySQL Forums
Forum List  »  General

Re: ROUND discrepancy
Posted by: Chris Thorley
Date: January 30, 2020 08:13AM

Thanks for the reply and I really appreciate it.

My ultimate goal here is to create a function which extracts 3 significant figures from any number.

I have this working well using SQL below.

SELECT ROUND(2.56789, 3 - 1 - FLOOR(LOG10(ABS(2.56789))));

But when I try the run this as a function I don't get the same result regardless of which number datatype I use.

Using an explicit decimal is difficult because I do not know which precision I will need because 3 significant figures might either side of the decimal point (ie 0.0123 or 12.5 or 123 or 0.235 etc).

I will review the documentation and see what I can come up with but I wonder if you have best practice for doing this inside a function which gives me the same values as the SQL.

Options: ReplyQuote

Written By
January 29, 2020 04:30AM
January 29, 2020 09:49AM
Re: ROUND discrepancy
January 30, 2020 08:13AM
January 30, 2020 09:28AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.