significant-digits

rounding to an arbitrary number of significant digits

How can you round any number (not just integers > 0) to N significant digits? For example, if I want to round to 3 significant digits, I'm looking for a formula that could take: 1,239,451 and return 1,240,000 12.1257 and return 12.1 .0681 and return .0681 5 and return 5 Naturally the algorithm should not be hard-coded to only handl...

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 ...

How many digits can be stored for a number in SQL Server 2005?

I have a number from an Oracle database of 47306832975095894070.85314746810624532. When I bring it into SQL Server, it certainly doesn't show that many digits. It shows as 4.73068329750959E+19, and the field is defined as FLOAT. I think that probably includes all the significant digits, but I'm being asked if the number can be store...

Nicely representing a floating-point number in python

I want to represent a floating-point number as a string rounded to some number of significant digits, and never using the exponential format. Essentially, I want to display any floating-point number and make sure it looks nice. There are several parts to this problem: I need to be able to specify the number of significant digits. The ...

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...