Question:
c# compact framework 1.0 decimal problem?
m b
2007-11-22 10:57:26 UTC
double and decimal for some reason you can not use + for example (asume price is already declared as a decimal)


price = (price+ 3.20);

gets
Operator '+' cannot be applied to operands of type 'decimal' and 'double'

so what do you do if you want to add a decimal
Three answers:
Smutty
2007-11-22 11:52:59 UTC
That's because the 3.20 is being interpreted by the complier as being of type double.



To solve this issue, use the following syntax:

price = price + 3.20m;



You can also explicitly cast the 3.20 to decimal type.



Hope this helps
gene_frequency
2007-11-22 19:17:16 UTC
1 The predefined addition operators are listed below. 2 For numeric and enumeration types, the predefined addition operators compute the sum of the two operands. 3 When one or both operands are of type string, the predefined addition operators concatenate the string representation of the operands



4 Integer addition:



int operator +(int x, int y);

uint operator +(uint x, uint y);

long operator +(long x, long y);

ulong operator +(ulong x, ulong y);



5 In a checked context, if the sum is outside the range of the result type, a System.OverflowException is thrown. 6 In an unchecked context, overflows are not reported and any significant high-order bits outside the range of the result type are discarded.



7 Floating-point addition:



float operator +(float x, float y);

double operator +(double x, double y);



(((dang! I don't like that. Hope this helps, tho. I'm wondering, is it imperitive you learn and use C#? Because in the little bit of time i just spent searching for what should be a simple solution to this, i learned: 1.) you're not the only who has bumped into this problem, and 2.) i'm totally turned off on the C# language now. It appears to be a broken implementation of C/C++. dang! ))))



Another place to ask that might help:

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/topics?hl=en
Zix M
2007-11-22 19:07:28 UTC
well, i dont know about C# but i think you have to look for data convert from type to other, or you have to declare price as float


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...