decimal

“Specified cast is not valid” when populating DataTable from OracleDataAdapter.Fill()

被刻印的时光 ゝ 提交于 2019-12-20 10:08:53
问题 I can't seem to find this question anywhere on Google (or StackOverflow), which really surprised me, so I'm putting it on here to help others in the same situation. I have a SQL query which runs fine on Oracle Sql Developer, but when I run it through C# using adapter.Fill(table) to get the results, I get Specified cast is not valid errors ( System.InvalidCastException ). Here is cut-down version of the C# code: var resultsTable = new DataTable(); using (var adapter = new OracleDataAdapter(cmd

How to insert DECIMAL into MySQL database

半腔热情 提交于 2019-12-20 08:57:57
问题 I have a database table with some fields, one of them, cost , is set to the DECIMAL data type. I set the parameters to 4,2 , which should allow 4 numbers before the decimal point, and 2 afterwards. (I've been told that the 4 here is the total amount, and the 2 is the amount after the decimal, could somebody please clear that up on a side note?) When I insert data via a POST request (the value 3.80 for example) the data stored to my database is actually 99.99 . What am I doing wrong to cause

ios - dynamically create and display unicode strings

不羁岁月 提交于 2019-12-20 07:24:08
问题 I have a UILabel in which I want to display a Unicode character. The following works: label.text = @"\U000025A0"; Now I want to dynamically generate the Unicode character from a decimal number as follows: label.text = NSString stringWithFormat:@"\U%08x",9632]; Xcode compiler fails with the following error: \U used with no following hex digits Is there a way to convert the decimal number 9632 to Unicode and then display it in a UILabel ? 回答1: I had a same issue to display entypo Font special

Why are the decimals not adding up correctly?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 07:14:02
问题 I'm working on a program where you can choose up to 3 things you want to divvy points amongst. Say for example that an action gains you 4 points, and those 4 points are divvied amongst the 3 things you selected. In this case, those 3 things each get 1.33333... points. In my database, they are stored as 1.33. However when I bring them out, it tallies up to 3.99. Understandable. But how can I avoid this without giving one of the things 1.34 points? 回答1: Store the full float/double in your

Convert decimal to binary in Matlab?

戏子无情 提交于 2019-12-20 05:24:45
问题 I am converting base-10 numbers to base-2 numbers, and specifying the number of bits I'd like to use to represent these base-10 numbers. Here's my code for negative numbers: function output = DTB(decimal,binary) if decimal < 0 smallestNum = -(2^(bits-1)); if decimal < smallestNum error('%d cannot be represented in %d bits. Increase the number of bits. ',decimal,bits); output = ''; end output = '1'; bits = bits - 1; if smallestNum == decimal while bits ~= 0 output = [output,'0']; bits = bits -

Global decimal rounding options in Django

独自空忆成欢 提交于 2019-12-20 04:54:05
问题 Decimal numbers are by default rounded very unexpectedly, in order to make it work normally, it is needed to use ROUND_HALF_UP option. >>> from decimal import * >>> Decimal("2.5").quantize(Decimal(1)) Decimal('2') >>> getcontext().rounding = ROUND_HALF_UP >>> Decimal("2.5").quantize(Decimal(1)) Decimal('3') >>> Decimal("2.4").quantize(Decimal(1)) Decimal('2') My question is - where in the Django application I have to set rounding option, so that it would work globally in the project? By

Drop 0 value in decimal places

喜你入骨 提交于 2019-12-20 04:28:07
问题 I want to ask if anybody know the query to drop the 0 value in decimal.. E.g : A field name percent have these values Percent 770.00000000000000000000, 340.670000000000000000000, 96.00000000000000000000, 4400.56000000000000000000, 109.89000000000000000000, 109.00000000000000000000, 37.00000000000000000000, Currently I'm using the query "select cast([Percent] as decimal(9,2)) as [Percent] from table" and will result in Result 770.00, 340.67, 96.00, 4400.56, 109.89, 109.00, 37.00, I want the

How pass an decimal from c# to vb6 with Interop

别来无恙 提交于 2019-12-20 02:27:25
问题 I have an interop c# class with a property: decimal ImportoDocumento { get; set; } if i try to access to this property from vb6 a receive an error: Compiler error: Function or interface marked as restricted or the function uses an automation type not supported in visual basic. So i found this partial solution: decimal ImportoDocumento { [return: MarshalAs(UnmanagedType.Currency)] get; [param: MarshalAs(UnmanagedType.Currency)] set; } but currency supports numbers with max 4 decimals. i have

Format, 2 decimal places for double and 0 for integer in java

雨燕双飞 提交于 2019-12-20 02:13:13
问题 I am trying to format a double to exact 2 decimal places if it has fraction, and cut it off otherwise using DecimalFormat So, I'd like to achieve next results: 100.123 -> 100.12 100.12 -> 100.12 100.1 -> 100.10 100 -> 100 Variant #1 DecimalFormat("#,##0.00") 100.1 -> 100.10 but 100 -> 100.00 Variant #2 DecimalFormat("#,##0.##") 100 -> 100 but 100.1 -> 100.1 Have any ideas what pattern to choose in my case? 回答1: The only solution i reached is to use if statement like was mentioned here: https:

How to round System.Decimal in .Net to a number of significant figures

試著忘記壹切 提交于 2019-12-19 22:08:13
问题 I have a System.Decimal number 0.00123456789 and I wish to round to 3 significant figures. I expect 0.00123 with the behaviour to be a rounding behaviour rather than truncation. Is there a bullet proof way to do this in .Net? 回答1: You can try this... But I don't guarantee anything... Written and tested in 20 minutes and based on Pyrolistical's code from https://stackoverflow.com/a/1581007/613130 There is a big difference in that he uses a long for the shifted variable (because a double has a