significant-digits

Increase significant digits in pyplot cursor

孤人 提交于 2020-12-26 11:00:54
问题 I have a function plotted using pyplot. When I move the cursor over the window, I can see the values for X and Y of the location of the cursor at the bottom-left of the window (display as, for example, x = 4.27567e+06 y = 6.98764e-09). How can I change the number of significant digits of those values? I've tried playing with the axis settings and tick settings, but it doesn't seem to help. As you can see in the example I gave above, right now the resolution is 6 significant digits, but I need

How can I round a float such that there are only two trailing digits after the decimal point?

六眼飞鱼酱① 提交于 2020-01-05 07:29:29
问题 I have a float number like 137.57667565656 but I would like to round it such that there are only two trailing digits after the decimal point like the new float number will be 137.58. I tried this so far: (Math.round((value*100)/100)).toFixed(2).toString(); But unfortunately, it rounds my value to 137.00. It adds the decimals places as zeroes, why? How can I achieve the above? 回答1: What did you expect? (value*100)/100 simply returns the original value of value , so Math.round((value*100)/100))

Neat way to find the number of significant digits in a BigDecimal?

寵の児 提交于 2020-01-03 17:18:48
问题 I do not want to limit the number of significant digits in a BigDecimal. I only want to find the number of significant digits that number has. Is there a way to do this without converting the number to string and count the number characters? 回答1: I believe you want a combination of stripTrailingZeros, precision and scale, as demonstrated here: import java.math.*; public class Test { public static void main(String[] args) { test("5000"); // 4 test("5000.00"); // 4 test("5000.12"); // 6 test(

Extracting floating-point significand and exponent in NumPy

廉价感情. 提交于 2020-01-02 23:21:52
问题 I would like to be able to extract the significand and exponent of floating-point numbers in NumPy. Getting the exponent as an integer is fine and ok for the significand. Getting the significand as a bitfield would be even more convienient. I am aware that Python floats have a hex method; however, I wish to use numpy.float32 , numpy arrays, and ufuncs. I am also aware of the numpy view method that allows me to see the float as an integer and thus as a binary string: >>> import numpy as np >>>

Extracting floating-point significand and exponent in NumPy

你离开我真会死。 提交于 2020-01-02 23:21:12
问题 I would like to be able to extract the significand and exponent of floating-point numbers in NumPy. Getting the exponent as an integer is fine and ok for the significand. Getting the significand as a bitfield would be even more convienient. I am aware that Python floats have a hex method; however, I wish to use numpy.float32 , numpy arrays, and ufuncs. I am also aware of the numpy view method that allows me to see the float as an integer and thus as a binary string: >>> import numpy as np >>>

Round to n Significant Figures in SQL

萝らか妹 提交于 2020-01-01 07:34:09
问题 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 significant figures. 回答1: select round(@number,@sf-1- floor(log10(abs(@number)))) should do the trick ! Successfully tested on your two examples. Edit : Calling this function on @number=0 won't work. You should add a test for this before using this code.

How to round down to the nearest significant figure in php

纵然是瞬间 提交于 2019-12-29 00:35:51
问题 Is there any slick way to round down to the nearest significant figure in php? So: 0->0 9->9 10->10 17->10 77->70 114->100 745->700 1200->1000 ? 回答1: $numbers = array(1, 9, 14, 53, 112, 725, 1001, 1200); foreach($numbers as $number) { printf('%d => %d' , $number , $number - $number % pow(10, floor(log10($number))) ); echo "\n"; } Unfortunately this fails horribly when $number is 0, but it does produce the expected result for positive integers. And it is a math-only solution. 回答2: Here's a

Extract n most significant non-zero bits from int in C++ without loops

余生颓废 提交于 2019-12-21 04:59:07
问题 I want to extract the n most significant bits from an integer in C++ and convert those n bits to an integer. For example int a=1200; // its binary representation within 32 bit word-size is // 00000000000000000000010010110000 Now I want to extract the 4 most significant digits from that representation, i.e. 1111 00000000000000000000010010110000 ^^^^ and convert them again to an integer (1001 in decimal = 9). How is possible with a simple c++ function without loops? 回答1: Some processors have an

How to create a decimal.Decimal object with a given number of significant figures?

浪尽此生 提交于 2019-12-12 20:23:05
问题 The best way I've found to produce a decimal.Decimal number with a specific number of significant figures is the one used to initialize the variable kluge below: import decimal THIS_IS_JUST_AN_EXAMPLE = 0.00001/3.0 with decimal.localcontext() as c: c.prec = 5 kluge = decimal.Decimal(THIS_IS_JUST_AN_EXAMPLE) + decimal.Decimal(0) naive = decimal.Decimal(THIS_IS_JUST_AN_EXAMPLE) print repr(kluge) print repr(naive) # Decimal('0.0000033333') # Decimal('0

On significant figures of numbers in python [closed]

断了今生、忘了曾经 提交于 2019-12-11 20:43:40
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Hi I have a somewhat strange question. I am converting a list of numbers (which represent physical measurements), where each are reported to some specified accuracy in arbitrary units depending on the study it comes from. Here is an example of what I mean: [...,105.0,20.0,3.5,4.25,9.78,7.2,7.2]