<p>Most programming languages, R included, do not track the number of significant digits for floating-point values. This is because in many cases significant digits are not necessary, would significantly slow down computations and require more RAM.</p>

<p>You may want to be interested in some libraries for computations with uncertainties, like the <a href="https://arxiv.org/pdf/1804.08552.pdf" rel="nofollow noreferrer"><code>errors</code></a> (PDF) package.</p>
Calculate significant digits of a number in R
<p>Maybe a daft question but why does R remove the significant 0 in the end of a number? For example 1.250 becomes 1.25 which has not the same accuracy. I have been trying to calculate the number of significant digits of a number by using <code>as.character()</code> in combination with <code>gsub()</code> and regular expressions (according to various posts) but i get the wrong result for numbers such as 1.250, since <code>as.character</code> removes the last 0 digit. Therefore the answer for 1.250 comes out as 2 digits rather than 3 which is the correct.</p>

<p>To be more specific why this is an issue for me:</p>

<p>I have long tables in word comprising of bond lengths which are in the format eg: 1.2450(20): </p>

<p><a href="https://i.stack.imgur.com/vnciQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vnciQ.png" alt="enter image description here"></a></p>

<p>The number in parenthesis is the uncertainty in the measurement which means that the real value is somewhere between 1.2450+0.0020 and 1.2450-0.0020. I have imported all these data from word in a large data frame like so:</p>

<pre><code>df&lt;-data.frame(Activity = c(69790, 201420, 17090),
               WN1=c(1.7598, 1.759, 1.760),
               WN1sd=c(17, 15, 3))
</code></pre>

<p>My aim is to plot the WN1 values against activity but also have the error bar on. This means that i will need to manually convert the WN1sd to: <code>WN1sd=c(0.0017, 0.015, 0.003)</code> which is not the R way to go, hence the need to obtain the number of significant digits of WN1. This works fine for the first two WN1 values but not for the 3rd value since R mistakenly thinks that the last 0 is not significant.</p>