oracle - SQL: Dynamic Round -


i round values resulting sql statement, dynamically.

i forgot official term this, might understand using explanation:

129.12144214 --> 129 0.000052142124 --> 0.0000521 2.213131 --> 2.21 

the amount of nonzero decimals, in case, of course 3.

how able in sql?

following these steps should results desire (example 129.12144214):

  • get log10: 2,11099836751079
  • cut decimals: 2
  • devide 129,... (10^2): 1.29121442
  • round 2 decimals: 1.29
  • multiply (10^2): 129

the idea bring every value value between 0 , 10, round 2 decimals , bring him original "range".

in sql it's (ok, have done in sql server, commands should same):

declare @x decimal(18,6); set @x = 129.12144214  ;  select (round(@x / power(10, floor(log10(@x))), 2)) * power(10, floor(log10(@x))) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -