decimal

How can I convert decimal? to decimal

巧了我就是萌 提交于 2019-12-03 06:28:25
问题 may be it is a simple question but I'm try all of conversion method! and it still has error! would you help me? decimal? (nullable decimal) to decimal 回答1: Try using the ?? operator: decimal? value=12; decimal value2=value??0; 0 is the value you want when the decimal? is null. 回答2: There's plenty of options... decimal? x = ... decimal a = (decimal)x; // works; throws if x was null decimal b = x ?? 123M; // works; defaults to 123M if x was null decimal c = x.Value; // works; throws if x was

Deconstructing Pokémon glitches?

血红的双手。 提交于 2019-12-03 06:22:59
问题 (I apologize if this is the wrong place to ask this. I think it's definitely programming related, though if this belongs on some other site please let me know) I grew up playing Pokémon Red and Blue, games that were great fun but are somewhat notorious for having numerous exploitable glitches (for example, see this ridiculous speedrun of the game that uses memory corruption to turn the item screen into a hex editor). Recently, I found an interesting speedrun of the game that uses a glitch

can't add two decimal numbers using jQuery

前提是你 提交于 2019-12-03 06:06:52
I am trying to add two decimal values but the returned sum is pure integer. What is wrong? I can't find it. any help will be welcome. jQuery(".delivery-method #ship_select").change(function(){ var cost = jQuery(this).val(); jQuery("#delivery_cost").val(cost); //returns 20.00 var tot = parseInt(cost) + parseInt(total); //total returns 71.96 }); With the code i am getting only 91 and not 91.96 Use parseFloat() instead of parseInt() . jQuery(".delivery-method #ship_select").change(function(){ var cost = jQuery(this).val(); jQuery("#delivery_cost").val(cost); //returns 20.00 var tot = parseFloat

conversion from float to Decimal in python-2.6: how to do it and why they didn't do it

对着背影说爱祢 提交于 2019-12-03 05:24:12
Direct conversion from float to Decimal was implemented in python-2.7, both in Decimal's constructor and with the Decimal.from_float() classmethod. Python-2.6 instead throws a TypeError suggesting to convert to string first: TypeError: Cannot convert float to Decimal. First convert the float to a string so my usual workaround is this: if sys.version_info < (2, 7): Decimal.from_float = classmethod(lambda cls, x: cls(str(x))) That's just a literary translation from the error message - and I just don't bother implementing it in the constructor too. If it's that simple, why didn't they implement

Decimal stores precision from parsed string in C#? What are the implications?

一笑奈何 提交于 2019-12-03 05:20:46
During a conversation on IRC, someone pointed out the following: decimal.Parse("1.0000").ToString() // 1.0000 decimal.Parse("1.00").ToString() // 1.00 How/why does the decimal type retain precision (or, rather, significant figures) like this? I was under the impression that the two values are equal, not distinct. This also raises further questions: How is the number of significant figures decided during mathematical operations? Does the number of significant figures get retained during serialization? Does the current culture affect the way this is handled? How is the number of significant

How do I format a C# decimal to remove extra following 0's?

扶醉桌前 提交于 2019-12-03 04:29:14
问题 I want to format a string as a decimal, but the decimal contains some following zeros after the decimal. How do I format it such that those meaningless 0's disappear? string.Format("{0}", 1100M); string.Format("{0}", 1100.1M); string.Format("{0}", 1100.100M); string.Format("{0}", 1100.1000M); displays: 1100 1100.1 1100.100 1100.1000 but I want it to be: 1100 1100.1 1100.1 1100.1 For reference, here are other questions that are essentially duplicates of this, that I've found thanks to answers

Truncate/round whole number in JavaScript?

大憨熊 提交于 2019-12-03 04:02:20
问题 For a script I'm writing, I need display a number that has been rounded, but not the decimal or anything past it. I've gotten down to rounding it to the third place, but I'm not sure how to go about just dropping the decimal and everything past it, as it doesn't seem like JavaScript has a substr function like PHP does. Any recommendations? 回答1: If you have a string , parse it as an integer: var num = '20.536'; var result = parseInt(num, 10); // 20 If you have a number , ECMAScript 6 offers

Which values cannot be represented correctly by a double

泄露秘密 提交于 2019-12-03 03:36:05
The Double data type cannot correctly represent some base 10 values. This is because of how floating point numbers represent real numbers. What this means is that when representing monetary values, one should use the decimal value type to prevent errors. (feel free to correct errors in this preamble) What I want to know is what are the values which present such a problem under the Double data-type under a 64 bit architecture in the standard .Net framework (C# if that makes a difference) ? I expect the answer the be a formula or rule to find such values but I would also like some example values

Convert string to decimal number in ruby

筅森魡賤 提交于 2019-12-03 00:53:46
I need to work with decimals. In my program, the user need to put a number with decimals to convert that number. The problem is: If I try to convert the argument into a number I get a integer without decimals. # ARGV[0] is: 44.33 size = ARGV[0] puts size.to_i # size is: 44 # :( You call to_i , you get integer. Try calling to_f , you should get a float. For more string conversion methods, look here . If you want more accurate answer with the calculation to avoid bug like this https://www.codecademy.com/en/forum_questions/50fe886f68fc44056f00626c you can use conversion to decimal example :

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

我只是一个虾纸丫 提交于 2019-12-03 00:12:20
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)) { var rows = adapter.Fill(resultsTable); // exception thrown here, but sql runs fine on Sql Dev