decimal

IP address conversion to decimal and vice versa

≡放荡痞女 提交于 2019-12-09 19:38:17
问题 Suppose my decimal number is 9766322441 so its corresponding is 70.30.65.9 but when this IP address IC converted back, its gives some different decimal number 1176387849 ... and when I convert the IP address pf google.com i.e 64.233.187.99 then it gives the 1089059683 and reverse conversion gives the correct IP address i.e 64.233.187.99 ... My question is what is wrong with the the above mention number? I also try with 9579342332 but the same result. It gives the wrong reverse conversion??

Python cdecimal InvalidOperation

痞子三分冷 提交于 2019-12-09 16:17:56
问题 I am trying to read financial data and store it. The place I get the financial data from stores the data with incredible precision, however I am only interested in 5 figures after the decimal point. Therefore, I have decided to use t = .quantize(cdecimal.Decimal('.00001'), rounding=cdecimal.ROUND_UP) on the Decimal I create, but I keep getting an InvalidOperation exception. Why is this? >>> import cdecimal >>> c = cdecimal.getcontext() >>> c.prec = 5 >>> s = '45.2091000080109' >>> # s = '0

C#: Storing percentages, 50 or 0.50?

妖精的绣舞 提交于 2019-12-09 14:40:20
问题 When holding percentage values in variables is there a preference between holding them as whole numbers vs fractions. That is should the variable hold numbers between 0 and 100 or between 0.00 and 1.00? In either case, the variable holding the values is of decimal type. The database I'm interacting with happens to store them as whole numbers 0 to 100. Note: I'm using the word "whole number" to denote values in the range 0 to 100 though those values may contain fractional components (e.g., 25

Why does .NET decimal.ToString(string) round away from zero, apparently inconsistent with the language spec?

喜夏-厌秋 提交于 2019-12-09 14:14:30
问题 I see that, in C#, rounding a decimal , by default, uses MidpointRounding.ToEven . This is expected, and is what the C# spec dictates. However, given the following: A decimal dVal A format string sFmt that, when passed in to dVal.ToString(sFmt) , will result in a string containing a rounded version of dVal ...it is apparent that decimal.ToString(string) returns a value rounded using MidpointRounding.AwayFromZero . This would appear to be a direct contradiction of the C# spec. My question is

How to check a string contains only digits and one occurrence of a decimal point?

大城市里の小女人 提交于 2019-12-09 12:30:23
问题 My idea is something like this but I dont know the correct code if (mystring.matches("[0-9.]+")){ //do something here }else{ //do something here } I think I'm almost there. The only problem is multiple decimal points can be present in the string. I did look for this answer but I couldn't find how. 回答1: If you want to -> make sure it's a number AND has only one decimal <- try this RegEx instead: if(mystring.matches("^[0-9]*\\.?[0-9]*$")) { // Do something } else { // Do something else } This

Rounded decimal in edit form Symfony2 + Doctrine2

谁说胖子不能爱 提交于 2019-12-09 11:50:19
问题 How do I set the decimal precision and scale within the symfony2 entity? I've defined latitude in longitude fields using decimal data type in my entity like this: /** * @ORM\Column(type="decimal", precision="10", scale="6", nullable=true) */ protected $latitude; When persisting new object it saves decimal correctly (I can see 52.406374 in phpMyAdmin). However when displaying edit form the number is rounded to 52,406 and after updating it is stored in mysql as 52.406000. Probably something is

Interesting behaviour of type “decimal” in C#

醉酒当歌 提交于 2019-12-09 07:53:47
问题 If we declare padding as const decimal, the padding is not working. mymoney = 1.2 and your money = 1.20, how can this behavior be explained? class Program { static void Main(string[] args) { decimal balance = 1.2m; const decimal ConstPadding = 0.00m; decimal padding = 0.00m; decimal mymoney = decimal.Round(balance + ConstPadding, 2); decimal yourmoney = decimal.Round(balance + padding, 2); Console.WriteLine(mymoney); // 1.2 Console.WriteLine(yourmoney); //1.20 } } 回答1: As an accompaniment to

pandas read_csv column dtype is set to decimal but converts to string

别等时光非礼了梦想. 提交于 2019-12-09 04:44:34
问题 I am using pandas (v0.18.1) to import the following data from a file called 'test.csv': a,b,c,d 1,1,1,1.0 I have set the dtype to 'decimal.Decimal' for columns 'c' and 'd' but instead they return as type 'str'. import pandas as pd import decimal as D df = pd.read_csv('test.csv', dtype={'a': int, 'b': float, 'c': D.Decimal, 'd': D.Decimal}) for i, v in df.iterrows(): print(type(v.a), type(v.b), type(v.c), type(v.d)) Results: `<class 'int'> <class 'float'> <class 'str'> <class 'str'>` I have

Is using decimal ranges in a switch impossible in C#?

浪尽此生 提交于 2019-12-09 02:14:15
问题 I'm just starting out learning C# and I've become stuck at something very basic. For my first "app" I thought I'd go for something simple, so I decided for a BMI calculator. The BMI is calculated into a decimal type which I'm now trying to use in a switch statement, but aparently decimal can't be used in a switch? What would be the C# solution for this: decimal bmi = calculate_bmi(h, w); switch (bmi) { case < 18.5: bmi_description = "underweight."; break; case > 25: bmi_description =

Javascript Adding Two Decimal Places

℡╲_俬逩灬. 提交于 2019-12-08 21:01:18
问题 This is my Code so far. I want to know how to return the answer with two decimal places. EX. Instead of 515.3 I want 515.30 or instead of 500 I want it to return 500.00. <HTML> <HEAD> <TITLE>Simple Adder</TITLE> <SCRIPT LANGUAGE="JavaScript"> function CalculateSum(Atext, form) { var A = parseFloat(Atext); form.Answer.value = A * .03+.30+A; } function ClearForm(form) { form.input_A.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> </SCRIPT> </HEAD> <BODY> <P><FONT SIZE="