Questions tagged [significant-digits]

Significant digits are a way of describing the precision of measurements in a scale-independent way.

Typically if a number is in normal scientific notation, the number of significant digits is the length (number of digits) of the mantissa or significand. The significant figures of a number are those digits that carry meaning contributing to its precision. This includes all digits except: All leading zeros, Trailing zeros when they are merely placeholders to indicate the scale of the number (exact rules are explained at Identifying significant figures), and spurious digits introduced, for example, by calculations carried out to greater precision than that of the original data, or measurements reported to a greater precision than the equipment supports.

Numbers are often rounded to avoid reporting insignificant figures. For instance, if a device measures to the nearest gram and gives a reading of 12.345 kg, it would create false precision to express this measurement as 12.34500 kg. Significant Figures - Wikipedia

159 questions
84
votes
18 answers

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 three 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…
DougN
  • 4,917
  • 11
  • 54
  • 77
74
votes
15 answers

Round a double to x significant figures

If I have a double (234.004223), etc., I would like to round this to x significant digits 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. For example, 0.086 to…
Rocco
  • 1,325
  • 3
  • 11
  • 19
39
votes
10 answers

Is floating point precision mutable or invariant?

I keep getting mixed answers of whether floating point numbers (i.e. float, double, or long double) have one and only one value of precision, or have a precision value which can vary. One topic called float vs. double precision seems to imply that…
32
votes
8 answers

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…
Chris Farmer
  • 23,314
  • 32
  • 110
  • 161
29
votes
2 answers

Show decimal places and scientific notation on the axis of a matplotlib plot

I am plotting some big numbers with matplotlib in a pyqt program using python 2.7. I have a y-axis that ranges from 1e+18 to 3e+18 (usually). I'd like to see each tick mark show values in scientific notation and with 2 decimal places. For example…
tempneff
  • 295
  • 1
  • 3
  • 4
23
votes
3 answers

Is the most significant decimal digits precision that can be converted to binary and back to decimal without loss of significance 6 or 7.225?

I've come across two different precision formulas for floating-point numbers. ⌊(N-1) log10(2)⌋ = 6 decimal digits (Single-precision) and N log10(2) ≈ 7.225 decimal digits (Single-precision) Where N = 24 Significant bits (Single-precision) The…
23
votes
4 answers

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…
Paul
  • 14,537
  • 13
  • 38
  • 49
17
votes
3 answers

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…
Dan Tao
  • 119,009
  • 50
  • 280
  • 431
12
votes
4 answers

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…
dln385
  • 9,734
  • 12
  • 43
  • 51
9
votes
3 answers

Round down a numeric

I have numeric's like this one: a <- -1.542045 And I want to round them down (or round up the abs) to 2 digits after the decimal point. signif(a,3) will round it down and give me 1.54 as a result but for this example the result I want is…
dan
  • 4,868
  • 4
  • 35
  • 85
9
votes
8 answers

How do I round an integer up to 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?
John
  • 3,210
  • 1
  • 27
  • 42
9
votes
10 answers

How to get excel to display a certain number of significant figures?

I am using excel and i want to display a value to a certain number of significant figures. I tried using the following equation =ROUND(value,sigfigs-1-INT(LOG10(ABS(value)))) with value replaced by the number I am using and sigfigs replaced with…
Veridian
  • 3,278
  • 10
  • 38
  • 73
8
votes
7 answers

How do I round a float to a specified number of significant digits in Ruby?

It would be nice to have an equivalent of R's signif function in Ruby. For example: >> (11.11).signif(1) 10 >> (22.22).signif(2) 22 >> (3.333).signif(2) 3.3 >> (4.4).signif(3) 4.4 # It's usually 4.40 but that's OK. R does not print the trailing 0's …
Aleksandr Levchuk
  • 3,902
  • 3
  • 30
  • 38
8
votes
7 answers

C++ significant figures

How can I do math involving significant figures in C++? I want this to work correct with measured data from chemistry and physics experiments. An example: 65 / 5 = 10. I would need to get rid of unneeded decimal places and replace some digits…
joshim5
  • 2,202
  • 4
  • 27
  • 39
7
votes
5 answers

rounding to an arbitrary number of significant digits in javascript is not working

I tried below sample code function sigFigs(n, sig) { if ( n === 0 ) return 0 var mult = Math.pow(10, sig - Math.floor(Math.log(n < 0 ? -n: n) / Math.LN10) - 1); return Math.round(n * mult) / mult; } But this function…
suresh inakollu
  • 108
  • 1
  • 5
1
2 3
10 11