decimal

SQL Server: Convert varchar to decimal (with considering exponential notation as well)

血红的双手。 提交于 2020-06-25 17:27:15
问题 I need to convert data of a table and do some manipulation. One of the column datatypes is Varchar , but it stores decimal numbers. I am struggling to convert the varchar into decimal . I have tried CAST( @TempPercent1 AS DECIMAL(28, 16)) Problem is that data also has some values in exponential notation, for example: 1.61022e-016 . The sql query is throwing error on encountering such value. The error is Error converting data type varchar to numeric. How should I handle exponential notation

How to convert hex string into decimal value

被刻印的时光 ゝ 提交于 2020-06-25 09:37:10
问题 I tried to convert an hex string into a decimal value but it doesn't gave me the expected result I tried convert.toint32(hexa,16) , convert.todecimal(hexa) . I have a string look like this : 1 12 94 201 198 And I convert it into : 10C5EC9C6 And I know that the result is: 4502505926 I need your help Thank you very much for your help :) 回答1: The System.Decimal (C# decimal ) type is a floating point type and does not allow the NumberStyles.HexNumber specifier. The range of allowed values of the

Python - Pymongo MongoDB 3.4 - NumberDecimal

好久不见. 提交于 2020-06-18 09:07:13
问题 i am using mongodb 3.4 in order to insert proper prices to my database.. According to: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst#reading-from-extended-json i used this in my python code: 'credits': {'$numberDecimal': Decimal128('9.99')}, but throws: bson.errors.InvalidDocument: key '$numberDecimal' must not start with '$' So what is the correct syntax for inserting numberdecimal in mongodb using python ? thanks and greetings 回答1: Simply this:

How do I convert a string to a Python Decimal in German locale (with comma instead of a point)

被刻印的时光 ゝ 提交于 2020-06-11 18:09:51
问题 I'm trying to convert a string to a python decimal. This works from decimal import * mystr = '123.45' print(Decimal(mystr)) But when I want to use the thousand separator and the locale, it doesn't. Converting to float works fine. from locale import * setlocale(LC_NUMERIC,'German_Germany.1252') from decimal import * mystr = '1.234,56' print(atof(mystr)) print(Decimal(mystr)) returns the float and an error 1234.56 InvalidOperation: [<class 'decimal.ConversionSyntax'>] Is there a right way to

Casting to Decimal is not supported in LINQ to Entities queries

只谈情不闲聊 提交于 2020-06-10 02:54:27
问题 I have a database table Transaction (transactionID, LocalAmount...). where datatype for Localamount property is float . ON the UI I am trying to return a SUM of column (Localamount) in one row on a button click event. I have used decimal instead of float However I am getting an error on the code where I am casting to decimal System.NotSupportedException was unhandled by user code Message=Casting to Decimal is not supported in LINQ to Entities queries, because the required precision and scale

Round a decimal number to the first decimal position that is not zero

泄露秘密 提交于 2020-06-08 15:47:03
问题 I want to shorten a number to the first significant digit that is not 0. The digits behind should be rounded. Examples: 0.001 -> 0.001 0.00367 -> 0.004 0.00337 -> 0.003 0.000000564 -> 0.0000006 0.00000432907543029 -> 0.000004 Currently I have the following procedure: if (value < (decimal) 0.01) { value = Math.Round(value, 4); } Note: numbers will always be positive the number of significant digits will always be 1 values larger 0.01 will always be rounded to two decimal places, hence the if <

How to converting a string of Binary numbers into a string of Decimal numbers?

浪子不回头ぞ 提交于 2020-05-29 10:26:45
问题 I am wanting to make a program that take a binary string and turns it into a decimal string. I know you how do this: Convert.ToString(00001000, 2); To convert a single binary number to a single decimal number, but how would I take a bunch of binary numbers in a string, like this: 00001000 00000101 00001100 00001100 00001111 00010111 00001111 00010010 00001100 00000100 into a string of decimal numbers, like this: 8 5 12 12 15 23 15 18 12 4 Thank for the help. 回答1: Its as easy as Convert

Efficiently convert two Integers x and y into the float x.y

浪子不回头ぞ 提交于 2020-05-25 23:47:02
问题 Given two integers X and Y, whats the most efficient way of converting them into X.Y float value in C++? E.g. X = 3, Y = 1415 -> 3.1415 X = 2, Y = 12 -> 2.12 回答1: Here are some cocktail-napkin benchmark results, on my machine, for all solutions converting two int s to a float , as of the time of writing. Caveat: I've now added a solution of my own, which seems to do well, and am therefore biased! Please double-check my results. Test Iterations ns / iteration ----------------------------------

Efficiently convert two Integers x and y into the float x.y

非 Y 不嫁゛ 提交于 2020-05-25 23:46:34
问题 Given two integers X and Y, whats the most efficient way of converting them into X.Y float value in C++? E.g. X = 3, Y = 1415 -> 3.1415 X = 2, Y = 12 -> 2.12 回答1: Here are some cocktail-napkin benchmark results, on my machine, for all solutions converting two int s to a float , as of the time of writing. Caveat: I've now added a solution of my own, which seems to do well, and am therefore biased! Please double-check my results. Test Iterations ns / iteration ----------------------------------

(vb.net) rounding to 2 decimal places

人盡茶涼 提交于 2020-05-23 11:33:16
问题 I am creating a program for a project that will help me learn visual basic. But when I work out how much a certain material is worth with dimensions. It come out with more than two decimal places. I know how to use math.floor function but it doesn't round to 2 decimal places. Does anyone know what function I should use to round to two decimal places? 回答1: The Decimal.Round method will do the trick for you. You can specify the number of decimal places. 回答2: You can use; Math.Round([DECIMAL], 2