decimal

Is it possible to cast a DECIMAL to DOUBLE in MySQL?

a 夏天 提交于 2020-01-01 10:53:08
问题 I know all the numerical implications, that is, the possible rounding issues inherent to floating point formats, but in my case I have DECIMAL columns in MySQL that I want to convert to DOUBLE straight in the MySQL query rather than down stream. Could anyone help? 回答1: SELECT my_decimal_field + 0E0 FROM my_table 回答2: It seems not possible to cast it to DOUBLE which brings problems if you do calculations and for example want to ROUND() a DECIMAL 12,2 in the third digit. Using ROUND(foo * bar,2

Regex a decimal number with comma

本小妞迷上赌 提交于 2020-01-01 09:58:10
问题 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

How to Convert pythons Decimal() type into an INT and exponent

…衆ロ難τιáo~ 提交于 2020-01-01 08:38:09
问题 I would like to use the Decimal() data type in python and convert it to an integer and exponent so I can send that data to a microcontroller/plc with full precision and decimal control. https://docs.python.org/2/library/decimal.html I have got it to work, but it is hackish; does anyone know a better way? If not what path would I take to write a lower level "as_int()" function myself? Example code: from decimal import * d=Decimal('3.14159') t=d.as_tuple() if t[0] == 0: sign=1 else: sign=-1

How to avoid rounding off in NSNumberFormatter

扶醉桌前 提交于 2020-01-01 08:37:22
问题 I am trying to have a number string with maximum 2 decimals precision, while rest decimals just trimmed off instead of rounding them up. For example: I have: 123456.9964 I want: 123456.99 -> Just want to trim rest of the decimal places What I have tried is: NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; [numberFormatter setMaximumFractionDigits:2]; NSString *numberAsString = [numberFormatter

Decimal.TryParse doesn't parse my decimal value

被刻印的时光 ゝ 提交于 2020-01-01 07:57:38
问题 When I tried to convert something like 0.1 (from user in textbox), My value b is always false. bool b = Decimal.TryParse("0.1", out value); How can it be here to work? 回答1: Too late to the party, but I was going to suggest forcing the culuture to en-US but Invariant is a better sln decimal value; bool b = Decimal.TryParse("0.1", NumberStyles.Any, new CultureInfo("en-US"), out value); 回答2: Specify the culture for the parsing. Your current culture uses some different number format, probably 0,1

decimal in c# misunderstanding?

霸气de小男生 提交于 2020-01-01 04:38:06
问题 (while trying to analyze how decimal works ) && after reading @jonskeet article and seeing msdn , and thinking for the last 4 hours , I have some questions : in this link they say something very simple : 1.5 x 10^2 has 2 significant figures 1.50 x 10^2 has 3 significant figures. 1.500 x 10^2 has 4 significant figures etc... ok...we get the idea. from jon's article : sign * mantissa / 10^exponent As usual, the sign is just a single bit, but there are 96 bits of mantissa and 5 bits of exponent

Want to restrict the value of a MySQL field to specific range (Decimal values)

做~自己de王妃 提交于 2020-01-01 03:33:06
问题 I want to restrict the value of a field in a row of a table to a specific range. Is it possible to restrict my relationship_level field to [0.00 to 1.00] ? At the moment I am using DECIMAL(2,2), it wouldn't allow DECIMAL(1,2) as M must be >= D. I assume a data type of DECIMAL(2,2) will actually allow values from 00.00 up to 99.99? CREATE TABLE relationships ( from_user_id MEDIUMINT UNSIGNED NOT NULL, to_user_id MEDIUMINT UNSIGNED NOT NULL, relationship_level DECIMAL(2,2) UNSIGNED NOT NULL,

Fractions instead of decimals

眉间皱痕 提交于 2019-12-31 06:07:26
问题 So, I am Writing this little program in c++, it's made to compute various values with lines (sorry i am french, i don't know how to say it in English, but they are the lines with equation types Y = kx + t). And I want my program to output fractions instead of decimals (2/3 instead of 0.666666666...). Can anyone tell me how ? I read online that there are some libraries for that purpose, can anyone help me on how to use them and/or how to implement them in my code ? Thanks :) #include "pch.h"

OleDB Read Excel decimal value

廉价感情. 提交于 2019-12-31 06:01:23
问题 I am using OleDB Ace 12 to read an Excel (xslx) sheet containing a column with decimal values. When I open the Excel sheet on my PC a decimal value is correctly formatted as 1.850,50 (NLD culture with comma as decimal separator) When I'm reading out the Excel sheet using OleDB (C#4.0), the string value of this field is always 1,850.50 (US format) I've tried setting the Locale of the DataSet I fill, set the currentthread's culture and more, but the DataSet filled with OleDB adapter always

OleDB Read Excel decimal value

♀尐吖头ヾ 提交于 2019-12-31 06:01:04
问题 I am using OleDB Ace 12 to read an Excel (xslx) sheet containing a column with decimal values. When I open the Excel sheet on my PC a decimal value is correctly formatted as 1.850,50 (NLD culture with comma as decimal separator) When I'm reading out the Excel sheet using OleDB (C#4.0), the string value of this field is always 1,850.50 (US format) I've tried setting the Locale of the DataSet I fill, set the currentthread's culture and more, but the DataSet filled with OleDB adapter always