decimal

How can I strip zeros and decimal points off of decimal strings?

陌路散爱 提交于 2019-12-04 11:02:09
The following code currently outputs: 12.1 12.100 12.1000 12.00 12 12.0000 How can I change it so it outputs: 12.1 12.1 12.1 12 12 12 Math.Round seems to be the thing, but it makes me define how many decimal places I want, but I want them to be variable as above. If there is no mathematical way to do it, I'll just strip the zeros and decimal points off the right side of the strings, but would think there is a math way to handle this. using System; using System.Collections.Generic; namespace Test8834234 { public class Program { static void Main(string[] args) { List<string> decimalsAsStrings =

Decimal to RGB in Javascript and PHP

旧街凉风 提交于 2019-12-04 09:56:23
I am trying to convert a decimal value back to an RGB value. Assuming that this is the formula for compiling the decimal value c = r*(255*255)+g*255+b (For example rgb(16,120,78) adds up to 1071078) How would one solve r, g and b without any "overflow"? Thanks in advance! Use division, modulo ( % ) and floor rounding: var r = Math.floor(c / (256*256)); var g = Math.floor(c / 256) % 256; var b = c % 256; Edit: halex spotted the diffence in use of 255 and 256 in the code. You should (as Millie Smith pointed out) use 256 instead of 255 when you put the components together: var c = r * (256*256) +

How to efficiently handle European decimal separators using the pandas read_csv function?

吃可爱长大的小学妹 提交于 2019-12-04 08:31:13
I'm using read_csv to read CSV files into Pandas data frames. My CSV files contain large numbers of decimals/floats. The numbers are encoded using the European decimal notation: 1.234.456,78 This means that the '.' is used as the thousand separator and the ',' is the decimal mark. Pandas 0.8. provides a read_csv argument called 'thousands' to set the thousand separator. Is there an additional argument to provide the decimal mark as well? If no, what is the most efficient way to parse a European style decimal number? Currently I'm using string replace which I consider to be a significant

Regex a decimal number with comma

时光总嘲笑我的痴心妄想 提交于 2019-12-04 08:05:13
I'm heaving trouble finding the right regex for decimal numbers which include the comma separator. I did find a few other questions regarding this issue in general but none of the answers really worked when I tested them The best I got so far is: [0-9]{1,3}(,([0-9]{3}))*(.[0-9]+)? 2 main problems so far: 1) It records numbers with spaces between them "3001 1" instead of splitting them to 2 matches "3001" "1" - I don't really see where I allowed space in the regex. 2) I have a general problem with the beginning\ending of the regex. The regex should match: 3,001 1 32,012,111.2131 But not: 32,012

cv::Mat matrix, HOW TO Reduce digits to the right of the decimal point in cv::Mat?

依然范特西╮ 提交于 2019-12-04 07:42:50
I have an app that prints a 3x3 cv::Mat on the iPhone screen. I need to reduce the decimals, as the screen is not so big, see: [1.004596557012473, -0.003116992336797859, 5.936915104939593; -0.007241746117066327, 0.9973985665720294, -0.2118670500989478; 1.477734234970711e-05, -1.03363734495053e-05, 1.000089074805124] so I would like to reduce the decimals .4 or .6 or six decimals. Any ideas? Cheers If you were using printf cv::Mat data(3, 3, CV_64FC1); for (int y = 0; y < data.rows; ++y) { for (int x = 0;x < data.cols; ++x) { printf("%.6f ", data.at<double>(y, x)); } } If you were using std:

MySQL decimal fields returned as strings in PHP

99封情书 提交于 2019-12-04 07:36:43
By default mysqli returns all values as strings, the MYSQLI_OPT_INT_AND_FLOAT_NATIVE option allows you to convert ints and floats to their appropriate types. Though this does not affect decimal fields. Is there a way to automatically cast all decimal fields to a php float type without manually calling $value = (float) $row->some_decimal_field ? I highly doubt it. Decimals use fixed point math, and there is no data type in PHP that can provide this. Floats come close, but they are in fact rounded, meaning that assigning 2 to a float could result in 1.99999999999999999 instead. So even if MySQL

Converting hex to dec C++

旧街凉风 提交于 2019-12-04 07:08:39
问题 Convert to hex: cout << hex << int(x) << endl; How to convert conversely, from hex to dec? Enter hex number simple: cin >> hex >> x; 回答1: You can use the std::dec IO manipulator: std::cout << std::dec << int(x) << endl; Note that this is only necessary if you have previously used std::hex or other means to manipulate the base of std::cout . Otherwise you need take no action: the default for an int is decimal. 回答2: Don't use the std::hex manipulator? std::cout << int(x) << std::endl; 来源: https

NumericUpDown: accept both comma and dot as decimal separator

本秂侑毒 提交于 2019-12-04 06:34:56
There's a way to force c# NumericUpDown to accept both comma and dot, to separate decimal values? I've customized a textbox to do it (practically replacing dots with commas), but I'm surprised that there isn't another way.. This question explains how to change the separator, but I would like to use both! NumericUpDown control uses the culture of the operating system to use comma or dots as a decimal separator. If you want to be able to handle both separators and consider them as a decimal separator (ie: not a thousand separator), you can use Validation or manual event treatment, for example:

How to convert Time to Decimal in SQL with an integer

左心房为你撑大大i 提交于 2019-12-04 06:33:59
问题 I am having a couple of issues converting time to decimal... Essentially I have used a DATEDIFF to identify the hours and minutes between two dates and times. This produces a result of 5.45, however I would like to get the result as 5.75. select RTRIM(DATEDIFF(second, startdate, enddate)/3600)+'.' + RIGHT('0'+RTRIM((DATEDIFF(second, startdate, enddate) % 3600)/60),2) from time I have tried a few things but I believe the issue is that this is not an integer and that's why i cant convert the

Floating-point division in bash

孤者浪人 提交于 2019-12-04 06:25:20
问题 I'm trying to convert whatever numbers the user inputs into 2 decimal places. For instance What is the total cost in cents? 2345 output: 23.45 this is the code i have so far percentage=20 #cannot change numerical value must convert into 0.20 echo -n "What is the total cost? "; read cost_in_cents echo "scale 1; $cost_in_cents" | bc I'm also going to be doing some multiplication with percentage, how can i also convert the percentage into a float (0.20) 回答1: Perhaps it's nostalgia for reverse