significant-digits

Rounding to n significant digits

白昼怎懂夜的黑 提交于 2019-11-27 16:12:15
I'm trying to write code in MATLAB that will round number to certain (as I ask) significant digits. I'm not sure how to do it. Any suggestions? To round to d significant digits : >> d = 3; %// number of digits >> x = 5.237234; %// example number >> D = 10^(d-ceil(log10(x))); >> y = round(x*D)/D y = 5.2400 To round to d decimal digits : >> d = 3; %// number of digits >> x = 5.237234; %// example number >> D = 10^d; >> y = round(x*D)/D y = 5.2370 EDIT Actually it's easier: the round function supports these options: >> d = 3; >> x = 5.237234; >> y = round(x, d, 'significant') y = 5.2400 >> d = 3;

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?

依然范特西╮ 提交于 2019-11-27 08:37:50
I've come across two different precision formulas for floating-point numbers. ⌊(N-1) log 10 (2)⌋ = 6 decimal digits (Single-precision) and N log 10 (2) ≈ 7.225 decimal digits (Single-precision) Where N = 24 Significant bits (Single-precision) The first formula is found at the top of page 4 of " IEEE Standard 754 for Binary Floating-Point Arithmetic " written by, Professor W. Kahan . The second formula is found on the Wikipedia article " Single-precision floating-point format " under section IEEE 754 single-precision binary floating-point format: binary32 . For the first formula, Professor W.

Can I show decimal places and scientific notation on the axis of a matplotlib plot using Python 2.7?

假装没事ソ 提交于 2019-11-27 04:15:29
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 2.35e+18 instead of just 2e+18 because values between 2e+18 and 3e+18 still read just 2e+18 for a few tickmarks. Here is an example of that problem. import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) x = np.linspace(0, 300, 20) y = np.linspace(0,300, 20) y = y*1e16 ax.plot(x,y) ax.get_xaxis().set_major

Nicely representing a floating-point number in python

风流意气都作罢 提交于 2019-11-27 02:44:16
问题 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 number of significant digits needs to be variable, which can't be done with with the string formatting operator. [edit] I've been corrected; the string

Formatting numbers with significant figures in C#

岁酱吖の 提交于 2019-11-26 22:49:14
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 or 5. Is there any convenient way to handle this? HAL9000 See: RoundToSignificantFigures by "P Daddy". I've combined his method with another one I liked. Rounding to significant figures is a lot easier in TSQL where the rounding method is based on rounding position

Rounding to n significant digits

二次信任 提交于 2019-11-26 18:36:14
问题 I'm trying to write code in MATLAB that will round number to certain (as I ask) significant digits. I'm not sure how to do it. Any suggestions? 回答1: To round to d significant digits : >> d = 3; %// number of digits >> x = 5.237234; %// example number >> D = 10^(d-ceil(log10(x))); >> y = round(x*D)/D y = 5.2400 To round to d decimal digits : >> d = 3; %// number of digits >> x = 5.237234; %// example number >> D = 10^d; >> y = round(x*D)/D y = 5.2370 EDIT Actually it's easier: the round

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?

泪湿孤枕 提交于 2019-11-26 17:46:11
问题 I've come across two different precision formulas for floating-point numbers. ⌊(N-1) log 10 (2)⌋ = 6 decimal digits (Single-precision) and N log 10 (2) ≈ 7.225 decimal digits (Single-precision) Where N = 24 Significant bits (Single-precision) The first formula is found at the top of page 4 of "IEEE Standard 754 for Binary Floating-Point Arithmetic" written by, Professor W. Kahan . The second formula is found on the Wikipedia article "Single-precision floating-point format" under section IEEE

Round a double to x significant figures

旧街凉风 提交于 2019-11-26 14:32:48
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 one decimal place becomes 0.1, but I would like it to stay at 0.08. The framework doesn't have a built-in function to round (or truncate, as in your example) to a number of significant digits. One way you can do this, though, is to scale your number so that your first significant digit is right after the decimal point, round (or truncate), then

Rounding to an arbitrary number of significant digits

大兔子大兔子 提交于 2019-11-26 12:14:24
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 return .0681 5 and return 5 Naturally the algorithm should not be hard-coded to only handle N of 3, although that would be a start. Here's the same code in Java without the 12.100000000000001 bug other answers have I also removed repeated code, changed power to a type integer to prevent floating issues when n - d is done, and made the long

Can I show decimal places and scientific notation on the axis of a matplotlib plot using Python 2.7?

删除回忆录丶 提交于 2019-11-26 11:04:24
问题 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 2.35e+18 instead of just 2e+18 because values between 2e+18 and 3e+18 still read just 2e+18 for a few tickmarks. Here is an example of that problem. import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) x =