I got a decimal property, like
[XmlElementAttribute(DataType = "decimal")] decimal Price
The problem is that I wanna force it to serialize always with precision of 2, but if the price is 10.50 it will be serialized to XML like <Price>10.5</Price>
.
Theres any way to force it (without creating a new property or changing the get of this property? I'm looking for some way to do this only sending a pattern to the XmlSerializer (or the XmlElementAttribute) or any smart way to do this ?
Thanks
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
I was having the opposite problem. My decimals were serializing with 4 decimal places, even though they were all 4 zeroes. I discovered that if I call decimal.Round(value, 2)
then it serializes to 2 decimal places. It would appear that the Decimal type remembers what you last rounded it too when it is serialized.
I was suspicious of the suggestion, but it worked that simply. Even though the value didn't need rounding, calling Round changed how many decimal places showed up in serialization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With