2

I want to round to 2 significant figures, e.g. 1286 => 1300, 0.01286 => 0.013

I can solve the problem like this:

set @x = -0.0127;
select @x, ROUND(@x,2-floor(LOG10(abs(@x)))) 

But that's really ugly. For such a basic concept, surely there's a better way?

7
  • nope. mysql rounding functions have no concept of significant figures. that's something you have to supply.
    – Marc B
    Nov 17, 2014 at 15:08
  • Isn't 0.01286 to 2 significant figures just 0??
    – Strawberry
    Nov 17, 2014 at 15:13
  • @Strawberry Yup: i'd even say 0.0 (which is saved as '0', nicely showing the issue of significancy and mysql)
    – Nanne
    Nov 17, 2014 at 15:32
  • Strawberry & Nanne - maybe you're thinking of rounding to decimal places? 0.01286 to 2 decimal places would be 0.01. (I corrected my example, where I'd mixed 2sf and 3sf) Nov 17, 2014 at 15:35
  • @MichaelGrazebrook Nope. I'm thinking of basic mathematics (en.wikipedia.org/wiki/Significant_figures)
    – Strawberry
    Nov 17, 2014 at 15:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.