significant-figures

Formatting numbers with significant figures in C#

I have some decimal data that I am pushing into a SharePoint list where it is to be viewed. I'd like to restrict the number of significant figures displayed in the result data based on my knowledge of the specific calculation. Sometimes it'll be 3, so 12345 will become 12300 and 0.012345 will become 0.0123. Occasionally it will be 4 o...

Round a double to x significant figures after decimal point

If I have a double (234.004223) etc. I would like to round this to x significant digits after the decimal places in C# So far I can only find ways to round to x decimal places but this simply removes the precision if there are any 0s in the number. e.g. 0.086 to 1 decimal place becomes 0.1 but I would like it to stay 0.08. Thanks ...

Round to n Significant Figures in SQL

I would like to be able to round a number to n significant figures in SQL. So: 123.456 rounded to 2sf would give 120 0.00123 rounded to 2sf would give 0.0012 I am aware of the ROUND() function, which rounds to n decimal places rather than significant figures. ...

String Format % with significant figures

I am using the following code to show percentage using String.Format but I also want to limit the number of significant figures to 2, the two don't seem to play well together. How can I get the two working together properly? String.Format("% Length <= 0.5: {0:0%}", m_SelectedReport.m_QLT_1); So what I ideally want is something like t...

How do I round an integer up to <nearest large number> in Ruby?

Say I have any of the following numbers: 230957 or 83487 or 4785 What is a way in Ruby I could return them as 300000 or 90000 or 5000, respectively? ...

Is there a way to get the "significant figures" of a decimal?

Update OK, after some investigation, and thanks in big part to the helpful answers provided by Jon and Hans, this is what I was able to put together. So far I think it seems to work well. I wouldn't bet my life on its total correctness, of course. public static int GetSignificantDigitCount(this decimal value) { /* So, the decimal t...