decimal Questions

1

Consider the following Python code: from decimal import Decimal d = Decimal("1.23") print(f"{d = }, {d.shift(1) = }") When I execute it in Python 3.12.4, I get this output: d ...
Jala asked 17/8 at 2:2

6

Solved

I'm sure someone has already solved this problem: what is an easy and portable way to convert a hex color value (anything from 000000 to FFFFFF) to 3 decimal values from 0 to 255. (If you're not fa...
Dehypnotize asked 31/8, 2011 at 6:16

16

Solved

Lets say that input from the user is a decimal number, ex. 5.2155 (having 4 decimal digits). It can be stored freely (int,double) etc. Is there any clever (or very simple) way to find out how many...
Laliberte asked 5/7, 2009 at 1:30

2

Solved

If I've got a Python Decimal, how can I reliably get the precise decimal string (ie, not scientific notation) representation of the number without trailing zeros? For example, if I have: >>...
Sankey asked 2/1, 2019 at 21:48

9

Solved

I have made a program that divides numbers and then returns the number, But the thing is that when it returns the number it has a decimal like this: 2.0 But I want it to give me: 2 so is there an...
Mammalian asked 15/7, 2013 at 9:53

7

Solved

How can I, without using formulas, show integers as integers, but decimals limited to a specific number of decimal places? E.g. show: 1 as 1 12 as 12 but 1.23456789 as 1.23 The number format 0.## i...
Kv asked 24/4, 2018 at 17:29

25

Solved

Does anyone know how to add 2 binary numbers, entered as binary, in Java? For example, 1010 + 10 = 1100.
Trygve asked 17/12, 2011 at 23:5

5

I'm writing a custom string to decimal validator that needs to use Decimal.TryParse that ignores culture (i.e. doesn't care if the input contains "." or "," as decimal point separator). This is the...
Postern asked 17/4, 2014 at 11:3

2

Series I'm working with: import pandas as pd from decimal import Decimal, BasicContext df = pd.Series([14978.22, 16025.429160000002, 209.97803999999996, 618.20369, 605.607, 1431.0916, 30.53575, 2...
Incombustible asked 10/8, 2018 at 20:7

6

Solved

I'm trying to do unit testing with xUnit.net. I want a 'Theory' test with '[InlineData]' which includes 'decimals': [Theory] [InlineData(37.60M)] public void MyDecimalTest(decimal number) { Asser...
Granth asked 16/6, 2016 at 8:49

21

Solved

I'm wondering if there is a concise and accurate way to pull out the number of decimal places in a decimal value (as an int) that will be safe to use across different culture info? For example: 19...
Selfcontent asked 20/11, 2012 at 16:31

2

Solved

Everywhere on the Internet it always says the decimal.Decimal.is_canonical() method will return True if the decimal is canonical. But what does that even mean? Is it just some term that I do not kn...
Chambertin asked 24/1, 2021 at 14:22

5

Solved

I am trying to have a number string with maximum 2 decimals precision, while rest decimals just trimmed off instead of rounding them up. For example: I have: 123456.9964 I want: 123456.99 -> J...
Scrounge asked 7/3, 2013 at 5:54

3

Solved

I'm dividing a very long into much smaller number. Both are of type decimal.Decimal(). The result is coming out in scientific notation. How do I stop this? I need to print the number in full. >&...
Scherzo asked 7/6, 2021 at 23:19

4

I red the mails about EU to US decimal mark conversion, these helped a lot, but I'm still feeling to need some help from the experts .. My datas are from an ERP system with numbers in the format li...
Vaseline asked 8/7, 2013 at 16:14

13

Solved

It's important to note that I'm not looking for a rounding function. I am looking for a function that returns the number of decimal places in an arbitrary number's simplified decimal representation...
Vindictive asked 2/3, 2012 at 19:53

9

Solved

I have a floating point number that I want to truncate to 3 places but I don't want to round up. For example, convert 1.0155555555555555 to 1.015 (not 1.016). How would I go about doing this in ...
Lyndy asked 12/11, 2011 at 18:43

7

It is possible to convert binary to decimal by this: var binary = "110"; var int = parseInt(binary, 2); document.getElementById("results").innerHTML = int; <div id="results"></div&...
Evapotranspiration asked 30/9, 2014 at 18:2

25

Solved

Is there a range() equivalent for floats in Python? >>> range(0.5,5,1.5) [0, 1, 2, 3, 4] >>> range(0.5,5,0.5) Traceback (most recent call last): File "<pyshell#10>", line...
Portecochere asked 1/9, 2011 at 7:30

3

Solved

I would like to have consistent output for a particular R script. In this case, I would like all numeric output to be in scientific notation with exactly two decimal places. Examples: 0.05 -->...
Redemption asked 21/9, 2016 at 18:7

3

Solved

In Python, the fractions.Fraction and decimal.Decimal standard library classes exist to help keep arithmetic with rational numbers precise. For the unfamiliar, an example of where it helps: >&g...
Wesson asked 7/11, 2016 at 15:23

6

Solved

In order to work with decimal data types, I have to do this with variable initialization: decimal aValue = 50.0M; What does the M part stand for?
Illegal asked 10/6, 2009 at 18:50

17

I have seen that some browsers localize the input type="number" notation of numbers. So now, in fields where my application displays longitude and latitude coordinates, I get stuff like &...
Graces asked 30/5, 2011 at 15:50

10

Solved

I am trying to print a number into engineering format with python, but I cannot seem to get it to work. The syntax SEEMS simple enough, but it just doesn't work. >>> import decimal >...
Disputable asked 7/9, 2012 at 3:0

2

Solved

I have the following Numpy array. a = np.array([0.1, 0.9, 0.17, 0.47, 0.5]) How can I find a number such that, when multiplied by the array, turns every element into an integer? For example, in th...
Arthur asked 31/10, 2021 at 8:34

© 2022 - 2024 — McMap. All rights reserved.