Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

We are creating XML file through C# code with the help of XSD.

Here one field is decimal and field format is XXXX.XX(9999.00)

Now if digits after decimal is other than zero then we are able to achieve this but if a value is zero then it's getting rounded.

e.g:- if a value is 9999.96 then we are able to store correctly if but value is 9999.00 then its getting converted to 9999

Is it possible to store as 9999.00

Please provide me suggestions.

Thanks
Posted
Comments
ZurdoDev 5-Jan-15 14:05pm    
Please click on improve question and show the code you're using to store the values.
Suvendu Shekhar Giri 5-Jan-15 14:24pm    
But you can always format the value while showing somewhere using string.Format("{0:0.00}", value) or string.Format("{0:f2}", value) etc.

In .NET (C#) decimal is a 128 bit numeric data type. The type itself, like with all the other types not defines how much significant digits you may or may not have after the decimal point...
First you must understand that here is no numerical (mathematical) difference between 999 and 999.00, so there should not be any problem receiving one or the another...However if you talking about a formatting for display purposes, than you should format the output...
C#
value.ToString("F2");

Where F means, fixed point, and 2 is the number of digits after the decimal point...
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Jan-15 14:54pm    
You are perfectly right, my 5, but I'm not sure OP will understand it. In my experience, people show don't properly see the difference between numbers (even integer numbers) and their presentations cannot get it until they grow a whole extra gyrus in their brains. :-)
—SA
Kornfeld Eliyahu Peter 5-Jan-15 14:58pm    
Thank you...
OP didn't understood...See OP's comment - posted as solution...
Any numeric value can be converted to a formatted string with ToString("format here") and in your case it would be ToString("#.00").
 
Share this answer
 
Hi Thanks for Reply ... but I don't want to convert same in String.. need to maintain in decimal only. So coverting to String will not help me as field type in XSD is decimal.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 5-Jan-15 14:54pm    
0. Learn to distinguish between number and its representation...
1. Do not post your comments as answers...
2. Learn XSD...
Sergey Alexandrovich Kryukov 5-Jan-15 15:21pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900