C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Python - Number of Significant Digits in results of division

By : Daniel Fabrício Bert
Date : November 19 2020, 07:01 PM
it fixes the issue The precision is determined by the hardware. Python uses hardware floats (actually doubles) for its floats. The implications are discussed in the tutorial: http://docs.python.org/tutorial/floatingpoint.html
If you want more control over precision and rounding, you should consider using the decimal module.
code :

Share :

## How to format numbers in R, specifying the number of significant digits but keep significant zeroes and integer part?

By : Christian Ditaputrat
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I've been struggling with formatting numbers in R using what I feel are very sensible rules. What I would want is to specify a number of significant digits (say 3), keep significant zeroes, and also keep all digits before the decimal point, some examples (with 3 significant digits): , format(num,3) comes very close.
code :
``````format(1.23456,digits=3)
# [1] "1.23"
format(12.3456,digits=3)
# [1] "12.3"
format(123.456,digits=3)
# [1] "123"
format(1234.56,digits=3)
# [1] "1235"
format(12345.6,digits=3)
# [1] "12346"
format(1.5000,digits=3)
# [1] "1.5"
format(1.4999,digits=3)
# [1] "1.5"
``````
``````sigDigits <- function(x,d){
z <- format(x,digits=d)
if (!grepl("[.]",z)) return(z)
require(stringr)
}

z <- c(1.23456, 12.3456, 123.456, 1234.56, 12345.6, 1.5000, 1.4999)
sapply(z,sigDigits,d=3)
# [1] "1.23"  "12.3"  "123"   "1235"  "12346" "1.50"  "1.50"
``````

## Format number to N significant digits in PHP

By : David Jenkins
Date : March 29 2020, 07:55 AM
wish of those help To get a number rounded to n significant figures you need to find the size of the number in powers of ten, and subtract that from n.
This works fine for simple rounding:
code :
``````function sigFig(\$value, \$digits)
{
if (\$value == 0) {
\$decimalPlaces = \$digits - 1;
} elseif (\$value < 0) {
\$decimalPlaces = \$digits - floor(log10(\$value * -1)) - 1;
} else {
\$decimalPlaces = \$digits - floor(log10(\$value)) - 1;
}

\$answer = round(\$value, \$decimalPlaces);
}
``````
``````function sigFig(\$value, \$digits)
{
if (\$value == 0) {
\$decimalPlaces = \$digits - 1;
} elseif (\$value < 0) {
\$decimalPlaces = \$digits - floor(log10(\$value * -1)) - 1;
} else {
\$decimalPlaces = \$digits - floor(log10(\$value)) - 1;
}

\$answer = (\$decimalPlaces > 0) ?
number_format(\$value, \$decimalPlaces) : round(\$value, \$decimalPlaces);
}
``````

## finding the number of significant digits versus digits after decimal in r

By : Alexandra Bln
Date : March 29 2020, 07:55 AM
hop of those help? This function will convert each value in the vector to a character value, remove all leading zeros, trailing zeros, and decimal places, and count the number of characters remaining. It's performance appears to be comparable to phiver's answer.
code :
``````sigfigs <- function(x){
orig_scipen <- getOption("scipen")
options(scipen = 999)
on.exit(options(scipen = orig_scipen))

x <- as.character(x)
x <- sub("\\.", "", x)
x <- gsub("(^0+|0+\$)", "", x)
nchar(x)
}

x <- c(1000,100,1300, 1200.1, 12345.67, 12345.670)

sigfigs(x)
``````

## Print floating point number with a set number of significant digits (non-scientific)

By : piyush sinha
Date : March 29 2020, 07:55 AM

## How can I read '0.00' as a number in Python while preserving number of significant digits?

By : Houssein Shaitou
Date : March 29 2020, 07:55 AM
Does that help If you need to track the number of significant digits past the decimal, neither float nor int is the correct way to store your number. Instead, use Decimal:
code :
``````from decimal import Decimal
a = Decimal('0.00')
print(str(a))
``````
``````a = float('0.00')
print('%.2f' % a)         # for compatibility with ancient Python
print('{:.2f}'.format(a)) # for compatibility with modern Python
print(f"{a:.2f}")         # for compatibility with *very* modern Python
``````