decimal

How to convert a binary fraction number into decimal fraction number in R?

空扰寡人 提交于 2019-12-02 06:24:56
问题 I need to write a function that converts a binary fraction number into decimal fraction number in R. e.g. f(0.001) # 0.125 What I did: I searched for the related functions in R packages: DescTools::BinToDec(0.001) # NA DescTools::BinToDec("0.001") # NA base::strtoi(0.001, base=2) # NA base::strtoi("0.001", base=2) # NA base::packBits(intToBits(0.001), "integer") # 0 base::packBits(intToBits("0.001"), "integer") # 0 compositions::unbinary(0.001) # 0.001 compositions::unbinary("0.001") # NA I

WPF Custom TextBox with Decimal Formatting

十年热恋 提交于 2019-12-02 06:23:15
问题 I am new to WPF. I have a requirement that I need to develop a custom textbox control which should support the functionality like: Should accept only decimal values. Should round off to 3 decimal places when assigned a value through code or by the user. Should show the full value(without formatting) on focus. Eg: If 2.21457 is assigned to textbox(by code or by user), it should display 2.215. When user clicks in it to edit it, it must show the full value 2.21457. After the user edits the value

Is it ok to use assertTrue on float and double values in JUnit?

倖福魔咒の 提交于 2019-12-02 06:09:36
问题 I tried using the assertEquals method on a float and eclipse says that the method was depreciated. Therefore, is the following alternative acceptable? Assert.assertTrue("Total does not match expected total :", receipt.getTotal() == 32.19f); Is there a specific reason why assertEquals must not be used to compare two floats or doubles in a test? In general, what is the best way to assert the equality of two decimal values in JUnit. I am using the 4.10 release of JUnit 回答1: In general you can

Global decimal rounding options in Django

三世轮回 提交于 2019-12-02 05:48:47
Decimal numbers are by default rounded very unexpectedly, in order to make it work normally, it is needed to use ROUND_HALF_UP option. >>> from decimal import * >>> Decimal("2.5").quantize(Decimal(1)) Decimal('2') >>> getcontext().rounding = ROUND_HALF_UP >>> Decimal("2.5").quantize(Decimal(1)) Decimal('3') >>> Decimal("2.4").quantize(Decimal(1)) Decimal('2') My question is - where in the Django application I have to set rounding option, so that it would work globally in the project? By saying globally I mean templates (floatformat template tag), views, model decimal field and so on. Decimal

Decimal point in calculations as . or ,

杀马特。学长 韩版系。学妹 提交于 2019-12-02 05:04:25
If I use decimal pad for input of numbers the decimal changes depending of country and region format. May be as a point "." or as a comma "," And I do not have control over at which device the app is used. If the region format uses a comma the calculation gets wrong. Putting in 5,6 is the the same as putting in only 5 some times and as 56 same times. And that is even if I programmatically allow both . and , as input in a TextField. How do I come around this without using the numbers an punctation pad and probably also have to give instructions to avoid input with comma "," It is only input for

Drop 0 value in decimal places

断了今生、忘了曾经 提交于 2019-12-02 04:03:36
I want to ask if anybody know the query to drop the 0 value in decimal.. E.g : A field name percent have these values Percent 770.00000000000000000000, 340.670000000000000000000, 96.00000000000000000000, 4400.56000000000000000000, 109.89000000000000000000, 109.00000000000000000000, 37.00000000000000000000, Currently I'm using the query "select cast([Percent] as decimal(9,2)) as [Percent] from table" and will result in Result 770.00, 340.67, 96.00, 4400.56, 109.89, 109.00, 37.00, I want the result this actually:-> 770, 340.67, 96, 4400.56, 109.89, 109, 37, You could use a combination of DECIMAL

Matching decimals in strings using matcher()

旧巷老猫 提交于 2019-12-02 03:59:54
I have a question regarding the matcher. Currently I am trying to read a string and store all the digits into an array. My question is, how do you try to match both integers and decimals? I have an array of doubles called: double[] thisArray = new double[20]; Into this array, i am trying to store all the numbers I extract from the string. Matcher temp = Pattern.compile("(\d+)").matcher(x); That is my function for the matcher. But this only matches integers. I want to match both integers and decimals like (5.2). But how do I do this? I want to be able to enter in both integers and decimals into

MySQL convert Degree, Minutes, Seconds to Degree decimal

余生长醉 提交于 2019-12-02 03:30:35
问题 I have multiple rows of Degrees Minutes Seconds that I need to convert with a query. 36°19'11.46" N = 36.31985 95°36'02.22" W = 95.600617 Each row is going to be different. I've been stuck on this for two days. Is this even possible? 回答1: Nice lifehack: reverse problem solution (degree to DMS) using SEC_TO_TIME built-in MySQL function: CREATE FUNCTION `geocoords`(lon double, lat double) RETURNS varchar(24) CHARSET cp1251 NO SQL DETERMINISTIC begin declare alon double; declare alat double;

user input value to use as decimal value python

霸气de小男生 提交于 2019-12-02 03:03:32
I am writing a python code where I ask the user for input and then I have to use their input to give the number of decimal places for the answer to an expression. userDecimals = raw_input (" Enter the number of decimal places you would like in the final answer: ") then I convert this to integer value userDecimals = int(userDecimals) then I write the expression, and I want the answer to have as many decimal places as the user input from UserDecimals, and I don't know how to accomplish this. The expression is math.sqrt(1 - xx **2) If this isn't clear enough I will try to explain it better, but I

MySQL convert Degree, Minutes, Seconds to Degree decimal

孤人 提交于 2019-12-02 02:12:34
I have multiple rows of Degrees Minutes Seconds that I need to convert with a query. 36°19'11.46" N = 36.31985 95°36'02.22" W = 95.600617 Each row is going to be different. I've been stuck on this for two days. Is this even possible? Nice lifehack: reverse problem solution (degree to DMS) using SEC_TO_TIME built-in MySQL function: CREATE FUNCTION `geocoords`(lon double, lat double) RETURNS varchar(24) CHARSET cp1251 NO SQL DETERMINISTIC begin declare alon double; declare alat double; declare slon varchar(12); declare slat varchar(12); set alon = abs(lon); set alat = abs(lat); set slon = TIME