decimal

Example for BASH two's complement with Hex values?

佐手、 提交于 2019-12-24 05:35:09
问题 I have a routine that is collecting a hex value via SNMP. Here is a real collection from my bash script 08 01 18 00 FF FF. The value is base on expr $((16#${array[4]})) - $((16#${array[5]})) so the results are 0, how do I introduce two is complement? The correct value for expr $((16#${array[4]})) - $((16#${array[5]})) is -1 based on the example I am working on. 回答1: For convenience, let's create a bash function: twos() { x=$((16#$1)); [ "$x" -gt 127 ] && ((x=x-256)); echo "$x"; } Now: $ twos

How to convert a string to float with “tail”?

邮差的信 提交于 2019-12-24 03:31:00
问题 I have a problem with converting string to float. print gettype($value[$id]); //returns string var_dump($value[$id]);//returns string '34,7140' (length=7) $float = floatval($value[$id]); print gettype($float);//returns double var_dump($float);//returns float 34 echo $float;//returns 34 I don't understand why "34" ? Why $float is not '34,7140'? How can I get $float = 34,7140 ? 回答1: The problem is that floats are expected to be in the English format with a . separating the decimal part, not a

How can I avoid jq truncating long decimal

筅森魡賤 提交于 2019-12-24 02:22:21
问题 How can I prevent jq from truncating long decimal values? For example: echo '18302628978110292481' | jq . result: 18302628978110292000 回答1: Javascript does not support such big numbers and so does jq . The integer size is 2^53 . Check this To make it work, you'll need to treat them as strings: echo '"18302628978110292481"' | jq . # Prints "18302628978110292481" 来源: https://stackoverflow.com/questions/27211870/how-can-i-avoid-jq-truncating-long-decimal

How can I avoid jq truncating long decimal

爷,独闯天下 提交于 2019-12-24 02:20:03
问题 How can I prevent jq from truncating long decimal values? For example: echo '18302628978110292481' | jq . result: 18302628978110292000 回答1: Javascript does not support such big numbers and so does jq . The integer size is 2^53 . Check this To make it work, you'll need to treat them as strings: echo '"18302628978110292481"' | jq . # Prints "18302628978110292481" 来源: https://stackoverflow.com/questions/27211870/how-can-i-avoid-jq-truncating-long-decimal

C# XML Serialization and Decimal Value

£可爱£侵袭症+ 提交于 2019-12-24 02:09:29
问题 I am using XmlSerializer to serialize a C# object that contains a decimal to a string of xml e.g. AnObject.ADecimalValue I am finding the precision is varying in particular even if I explicitly round as below some values are getting output with four values after the point e.g. 12564.39 gets output as 12564.3900 AnObject.ADecimalValue = decimal.Round(AnObject.ADecimalValue, 2); The serializing code is below. XmlSerializer serializer = new XmlSerializer(typeof(AnObject)); using (StringWriter

C# XML Serialization and Decimal Value

风格不统一 提交于 2019-12-24 02:09:07
问题 I am using XmlSerializer to serialize a C# object that contains a decimal to a string of xml e.g. AnObject.ADecimalValue I am finding the precision is varying in particular even if I explicitly round as below some values are getting output with four values after the point e.g. 12564.39 gets output as 12564.3900 AnObject.ADecimalValue = decimal.Round(AnObject.ADecimalValue, 2); The serializing code is below. XmlSerializer serializer = new XmlSerializer(typeof(AnObject)); using (StringWriter

Check precision to nth decimal place?

馋奶兔 提交于 2019-12-24 02:08:56
问题 I have to calculate the values of a hot plate and have it accurate only to the first decimal place. I am stumped on trying to figure out how to check all the array values if they changed. I found out that 724 runs made no change after that to the 4th decimal (how many were being printed). Is there a way to compare doubles variables only up to the n-th decimal place? #include <iostream> #include <string> #include <fstream> using namespace std; const int ARRAY_SIZE = 20; const int NEIGHBORS = 4

Regular Expression for decimal numbers

一曲冷凌霜 提交于 2019-12-24 02:00:54
问题 I need a validation RegEx for decimal. It should allow up to 5 digits after decimal. Allow: 1 1.0 12.0 12.01 123.01 1,123.01 1,123.013 21,123.01234 3,21,123.01234 How Can I do regex for this? 回答1: ^[\d,]+(\.\d{1,5})?$ 回答2: http://regexlib.com/Search.aspx?k=decimal 回答3: Do you want to validate the positions of the commas? If so, this works for the Indian numbering system that you seem to be using: ^(?:\d{1,2},(?:\d{2},)*\d{3}|\d{1,3})(\.\d{1,5})?$ If you want to permit commas in the integer

Binary to decimal - prolog

泄露秘密 提交于 2019-12-24 01:47:29
问题 I found this on stack: reversible "binary to number" predicate But I don't understand :- use_module(library(clpfd)). binary_number(Bs0, N) :- reverse(Bs0, Bs), binary_number(Bs, 0, 0, N). binary_number([], _, N, N). binary_number([B|Bs], I0, N0, N) :- B in 0..1, N1 #= N0 + (2^I0)*B, I1 #= I0 + 1, binary_number(Bs, I1, N1, N). Example queries: ?- binary_number([1,0,1], N). N = 5. ?- binary_number(Bs, 5). Bs = [1, 0, 1] . Could somebody explain me the code Especialy this : binary_number([], _,

MySql How to convert varchar (latitude, longitude) to Decimal fields?

☆樱花仙子☆ 提交于 2019-12-24 01:19:40
问题 In mysql I have a varchar containing latitude and longitude provided by Google maps. I need to be able to query based on a bounding box value, but have no need for the geo features now available. I'm trying to populate 2 new Decimal fields with the Decimal values found in the varchar. Here is the query that I'm trying to use, but the result are all rounded values in the new fields. Sample data: '45.390746926938185, -122.75535710155964', '45.416444621636415, -122.63058006763458' Create Table: