decimal

Regex to find integers and decimals in string

懵懂的女人 提交于 2019-12-23 12:33:29
问题 I have a string like: $str1 = "12 ounces"; $str2 = "1.5 ounces chopped; I'd like to get the amount from the string whether it is a decimal or not (12 or 1.5), and then grab the immediately preceding measurement (ounces). I was able to use a pretty rudimentary regex to grab the measurement, but getting the decimal/integer has been giving me problems. Thanks for your help! 回答1: If you just want to grab the data, you can just use a loose regex: ([\d.]+)\s+(\S+) ([\d.]+) : [\d.]+ will match a

implementation of BigDecimal in idris

隐身守侯 提交于 2019-12-23 12:03:54
问题 I'm trying to implement a bigdecimal in Idris. I have this so far: -- a big decimal has a numerator and a 10^x value -- it has one type for zero, --TODO the numerator can't be zero for any other case --TODO and it can't be divisible by 10 data BigDecimal : (num : Integer) -> (denExp : Integer) -> Type where Zero : BigDecimal 0 0 BD : (n : Integer) -> (d : Integer) -> BigDecimal n d I would like to force the restrictions marked by "TODO" above. However, I'm am just learning Idris, so I'm not

symfony2 doctrine decimal precision scale annotations are ignored

我们两清 提交于 2019-12-23 10:57:08
问题 i've set up an attribute in my entity like this : /** * @var decimal * * @ORM\Column(name="latitude", type="decimal", precision=10, scale=7, nullable=true) */ private $latitude; but when i generate the database schema with : doctrine:database:create; doctrine:schema:create my field is set up to decimal (10,0) in the database (when i look up with phpmyadmin) and so, when in insert data like 42.123456 with a form, this data is truncated to 42 . how can i resolve this? Thanks. 回答1: Ok, finally

How do I shift the decimal place in Python?

天涯浪子 提交于 2019-12-23 10:49:07
问题 I'm currently using the following to compute the difference in two times. The out - in is very fast and thus I do not need to display the hour and minutes which are just 0.00 anyway. How do I actually shift the decimal place in Python? def time_deltas(infile): entries = (line.split() for line in open(INFILE, "r")) ts = {} for e in entries: if " ".join(e[2:5]) == "OuchMsg out: [O]": ts[e[8]] = e[0] elif " ".join(e[2:5]) == "OuchMsg in: [A]": in_ts, ref_id = e[0], e[7] out_ts = ts.pop(ref_id,

How do I shift the decimal place in Python?

霸气de小男生 提交于 2019-12-23 10:49:06
问题 I'm currently using the following to compute the difference in two times. The out - in is very fast and thus I do not need to display the hour and minutes which are just 0.00 anyway. How do I actually shift the decimal place in Python? def time_deltas(infile): entries = (line.split() for line in open(INFILE, "r")) ts = {} for e in entries: if " ".join(e[2:5]) == "OuchMsg out: [O]": ts[e[8]] = e[0] elif " ".join(e[2:5]) == "OuchMsg in: [A]": in_ts, ref_id = e[0], e[7] out_ts = ts.pop(ref_id,

Write a dataframe with different number of decimal places per column in R

ぐ巨炮叔叔 提交于 2019-12-23 10:06:47
问题 I need to generate a dataframe or data.table which has different number of decimal places per column. For example: Scale Status 1.874521 1 Needs to be print in a CSV as: Scale, Status 1.874521, 1.000 This has to be as a numeric value as I have tried format(DF$status, digits=3) and as.numeric(format(DF$status, digits=3)) however this converts it to characters which when exported to CSV has double quotes ". My actual dataframe has lots of columns with different amounts of decimal places

EntityFramework returns corrupted/swaped data from SQL Server View

喜欢而已 提交于 2019-12-23 09:50:38
问题 I have simple query from a view in SQL Server: SELECT [PricePerM] FROM RealtyStatParent ORDER BY PricePerM When I execute the query in SQL Management Studio I get correct results. It means I get 2532 rows starting from 1.00 and ending by 173543.6893. When I make a query from C# using entity framework, I got the same results: var justDecimals = context.RealtyStatParents .OrderBy(item => item.PricePerM) .Select(item => item.PricePerM) .ToArray(); Until now nothing special. But what I really don

C# Convert string to double/decimal and back to string, keeping trailing zeroes, adding comas for thousands

谁说胖子不能爱 提交于 2019-12-23 09:48:12
问题 I am trying to get user input, parse it and then display with String.Format(), formatting thousands with comas. So, if user provides 1000 I will display 1,000 1000.00 => 1,000.00 1000.0 => 1,000.0 1,000.5 => 1,000.5 Basically I want to keep all decimals(including trailing zeroes) that were provided and just add formatting for thousands. I tried: String.Format("{0:#,0.######}" , Decimal.Parse(input)); String.Format("{0:#,0.######}" , Double.Parse(input); 回答1: double.Parse(input) is a no go, as

Parsing a decimal from a DataReader

孤者浪人 提交于 2019-12-23 09:38:45
问题 I found a workaround for this error, but am now really curious as to why this would be happening, was wondering if anyone else has had this error. My function is as follows: public void Blog_GetRating(int blogID, ref decimal rating, ref int voteCount) { // Sql statements // Sql commands if (DataReader.Read()) { // this line throws a 'Input string was not in a correct format.' error. rating = decimal.Parse(DataReader["Rating"].ToString()); // this works absolutly fine?! decimal _rating = 0;

c#: sum of two double numbers problem [duplicate]

一曲冷凌霜 提交于 2019-12-23 07:58:04
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why is floating point arithmetic in C# imprecise? Hi. I've got following problem: 43.65+61.11=104.75999999999999 for decimal is correct: (decimal)43.65+(decimal)61.11=104.76 Why result for double is wrong? 回答1: This question and its answers are a wealth of info on this - Difference between decimal, float and double in .NET? To quote: For values which are "naturally exact decimals" it's good to use decimal. This