decimal

Estimating error on calculations using decimals

前提是你 提交于 2020-01-02 08:49:58
问题 We're currently using System.Decimals to represent numbers in a .NET application we're developing. I know that decimals are design to minimize errors due to rounding, but I also know that certain numbers, 1/3 for example, cannot be represented as a decimal so some calculations will have small rounding error. I believe the magnitude of this error will be very small and insignificant, however a colleague disagrees. I would therefore like to be able to estimate the order of magnitude of the

Optimized algorithm for converting a decimal to a “pretty” fraction

旧时模样 提交于 2020-01-02 04:39:09
问题 Rather than converting an arbitrary decimal to an exact fraction (something like 323527/4362363), I am trying to convert to just common easily-discernible (in terms of human-readability) quantities like 1/2, 1/4, 1/8 etc. Other than using a series of if-then, less than/equal to etc comparisons, are there more optimized techniques to do this? Edit: In my particular case, approximations are acceptable. The idea is that 0.251243 ~ 0.25 = 1/4 - in my usage case, that's "good enough", with the

Convert String to Decimal Mystery

别说谁变了你拦得住时间么 提交于 2020-01-02 01:47:26
问题 I'm facing a problem about the conversion from string to decimal using C# .NET. The problem is that I have wrote the following code and works fine on my development Windows 7 .NET Framework 3.5 system. But, if I move the application on the Windows 2003 Server .NET 3.5 Framework the result is different. Can anyone understand what happen there? Code: dec = Convert.ToDecimal(strDec); Windows 7 result: 85.00 Windows 2003 result: 8500 回答1: It may be that the region and culture settings on your

C# Casting to a decimal

瘦欲@ 提交于 2020-01-02 01:06:10
问题 What, if any, is the difference between? decimal d = (decimal) myDouble; decimal d = new decimal(myDouble); decimal d = Convert.ToDecimal(myDouble); 回答1: There is no difference. If you look at the source: In Decimal: public static explicit operator decimal(double value) { return new decimal(value); } In Convert: public static decimal ToDecimal(float value) { return (decimal) value; } So in the end they all call new decimal(double) . 回答2: They all achieve the same results. However, here's a

Python 3 Decimal rounding half down with ROUND_HALF_UP context

你离开我真会死。 提交于 2020-01-02 01:05:29
问题 Can anybody explain or propose a fix for why when I round a decimal in Python 3 with the context set to round half up, it rounds 2.5 to 2, whereas in Python 2 it rounds correctly to 3: Python 3.4.3 and 3.5.2: >>> import decimal >>> context = decimal.getcontext() >>> context.rounding = decimal.ROUND_HALF_UP >>> round(decimal.Decimal('2.5')) 2 >>> decimal.Decimal('2.5').__round__() 2 >>> decimal.Decimal('2.5').quantize(decimal.Decimal('1'), rounding=decimal.ROUND_HALF_UP) Decimal('3') Python 2

Is there a library class to represent floating point numbers?

那年仲夏 提交于 2020-01-01 18:55:41
问题 I am writing an application which does a lot of manipulation with decimal numbers (e.g. 57.65). As multiplications and divisions quickly erode their accuracy, I would like to store the numbers in a class which preserves their accuracy after manipulation, rather than rely on float and double. I am talking about something like this: class FloatingPointNumber { private: long m_mantissa; int m_dps; // decimal points // so for example 57.65 would be represented as m_mantissa=5765, m_dps=2 public:

Is there a library class to represent floating point numbers?

半世苍凉 提交于 2020-01-01 18:54:28
问题 I am writing an application which does a lot of manipulation with decimal numbers (e.g. 57.65). As multiplications and divisions quickly erode their accuracy, I would like to store the numbers in a class which preserves their accuracy after manipulation, rather than rely on float and double. I am talking about something like this: class FloatingPointNumber { private: long m_mantissa; int m_dps; // decimal points // so for example 57.65 would be represented as m_mantissa=5765, m_dps=2 public:

Decimal points - Probability value of 0 in Language R

北战南征 提交于 2020-01-01 18:27:07
问题 How to treat p value in R ? I am expecting very low p values like: 1.00E-80 I need to -log10 -log10(1.00E-80) -log10(0) is Inf, but Inf at sense of rounding too. But is seems that after 1.00E-308, R yields 0. 1/10^308 [1] 1e-308 1/10^309 [1] 0 Is the accuracy of p-value display with lm function the same as the cutoff point, 1e-308, or it is just designed such that we need a cutoff point and I need to consider a different cutoff point - such as 1e-100 (for example) to replace 0 with <1e-100.

Masked TextBox with decimal numbers

寵の児 提交于 2020-01-01 15:07:06
问题 In my window application I need masked textbox which accept real decmal numbers. eg. 1) 1.56 2) 22.34 3) 123.34 4) 12312.34 This all value should be valid. Can anyone tell me how can I do this? And ya if anyone have better solution for real decimal numbers, instead of this masked TextBox than I love to see it. Thanks... 回答1: Use a custom control like this one (modify it to fulfill your needs): using System; using System.ComponentModel; using System.Text; using System.Windows.Forms; using

Convert really big number from binary to decimal and print it

与世无争的帅哥 提交于 2020-01-01 11:35:29
问题 I know how to convert binary to decimal. I know at least 2 methods: table and power ;-) I want to convert binary to decimal and print this decimal. Moreover, I'm not interested in this `decimal'; I want just to print it. But, as I wrote above, I know only 2 methods to convert binary to decimal and both of them required addition. So, I'm computing some value for 1 or 0 in binary and add it to the remembered value. This is a thin place. I have a really-really big number (1 and 64 zeros). While