Decimal Serialization Inconsistency?

I must be missing something here...

The inconsistency described below is minorly annoying in a current
project.  Can anyone come up w/ an explanation?

I've got two seemingly identical object graphs which serialize to
XML.  Each has some decimal properties, ex:

class Widget
{
   public decimal SubTotal { get; set; }
   public decimal Tax { get; set; }
}

When I serialize each graph, some of the decimals which are zero come
out as "0" while others come out as "0.00".  Specifically:

widgetA <SubTotal>0</SubTotal><Tax>0</Tax>
widgetB <SubTotal>0.00</SubTotal><Tax>0</Tax>

Comparing the objects in memory, the following all evaluate to true:
widgetA.SubTotal == widgetB.SubTotal
widgetA.Tax == widgetB.Tax
widgetA.SubTotal * 1000000 == widgetB.SubTotal * 1000000
widgetA.SubTotal * 1000000m == widgetB.SubTotal * 1000000m

I'm trying to find some rhyme or reason to this behavior.  Any ideas?
Thanks in advance!

James

0
jameskoch (1)
10/30/2007 8:38:53 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
629 Views

Similar Articles

[PageSpeed] 54

The only thing I can figure out is that the "decimal" data type stores
the precision used to assign to it as well as the value itself.  Your
post, though, inspired a solution to the problem.  I'm using a class
generated by Microsoft's xsd.exe utility.  The class contains a
decimal field and our client wants us to write out values with two
decimal places.

So, I tried the following, and it appears to work:

/// Override for Amount output
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal Amount {
  get {
    return this.amountField;
  }
  set {
    this.amountField = decimal.Parse(string.Format("{0:###0.00}",
value));
  }
}





On Oct 30, 12:38 pm, James  Koch <jamesk...@gmail.com> wrote:
> I must be missing something here...
>
> The inconsistency described below is minorly annoying in a current
> project.  Can anyone come up w/ an explanation?
>
> I've got two seemingly identical object graphs which serialize to
> XML.  Each has some decimal properties, ex:
>
> class Widget
> {
>    public decimal SubTotal { get; set; }
>    public decimal Tax { get; set; }
>
> }
>
> When I serialize each graph, some of the decimals which are zero come
> out as "0" while others come out as "0.00".  Specifically:
>
> widgetA <SubTotal>0</SubTotal><Tax>0</Tax>
> widgetB <SubTotal>0.00</SubTotal><Tax>0</Tax>
>
> Comparing the objects in memory, the following all evaluate to true:
> widgetA.SubTotal == widgetB.SubTotal
> widgetA.Tax == widgetB.Tax
> widgetA.SubTotal * 1000000 == widgetB.SubTotal * 1000000
> widgetA.SubTotal * 1000000m == widgetB.SubTotal * 1000000m
>
> I'm trying to find some rhyme or reason to this behavior.  Any ideas?
> Thanks in advance!
>
> James

0
12/14/2007 10:14:00 PM
Reply:

Similar Artilces:

SOP NonInventory Unit Cost 6 Decimal Places
Is there any simple way to increase the currency decimal places to greater than the current highest value of 5? Thanx Scott, I don't believe there is any easy or even moderately difficult way to do this, as the field types used to store amounts in GP only go up to 5 decimal places. -- Victoria Yudin Dynamics GP MVP Flexible Solutions - home of GP Reports http://www.flex-solutions.com/gpreports.html blog: http://www.victoriayudin.com "Scott Rutledge" <sersoar@hotmail.com> wrote in message news:E102B81B-8555-400E-843C-240C58794294@microsoft.com... > Is there any...

serialize address ID for customers
We would like our address ids to be automatically allotted sequentially starting 10001. We do not have VBA. Can this be done straight through sql? Sincerely, James No, you would have to use Dexterity or vba to do this as there isn't anything in GP that "defaults" address id's. patrick developer support -- This posting is provided "AS IS" with no warranties, and confers no rights. "james" <james@discussions.microsoft.com> wrote in message news:CEB00187-F74E-492A-BC4E-643F9091840F@microsoft.com... > We would like our address ids to be auto...

Reduce currency decimals
Hi, Is there any tool which will reduce the currency decimals on our Great Plains system. We want to reduce our system currency decimals. Thank you. KT I'm not sure if this is what you mean, but there's Tools >> Utilities >> Inventory >> Change Decimal Places This utility can change the decimal places for items. I don't know of any system-wide change for decimal places. Eleni "KT" wrote: > Hi, > > Is there any tool which will reduce the currency decimals on our Great > Plains system. We want to reduce our system currency decimals....

decimal problem
Hi all I a very strange effect when using different decimal settings and calculating some values: DECLARE @Decimal1 decimal(5, 2) DECLARE @Decimal2 decimal(30, 2) SET @Decimal1 = 0.2 SET @Decimal2 = 0.2 SELECT (CONVERT(decimal(15, 15), 0.000000000322900) * (1 - @Decimal1)) SELECT (CONVERT(decimal(15, 15), 0.000000000322900) * (1 - @Decimal2)) The first result is correct (0.00000000025832000), the second is wrong, why ??? Thanks for any comments Best regards Frank Uray Hi Frank This is what happens when you multiple these precision&scales Precision 15 + 3...

Decimal
In a laboratory test we do the temperature has to be reported to the nearest 0.5�C. Can anyone let me know how to format it so that when the result is a whole number, it leaves the decimal point out? eg 22�C or 22.5�C (not 22.�C or 22.0�C) Alan "Alan Cocks" <alandrob@netspace.net.au> wrote in message news:btlqhd$19fi$1@otis.netspace.net.au... > In a laboratory test we do the temperature has to be reported to the > nearest 0.5�C. > Can anyone let me know how to format it so that when the result is a whole > number, it leaves the decimal point out? &g...

VBA code and decimals
I have some VBA code as this: rrows=lastrow/4 if lastrow is 138 then rrows should be 34.5 but I always get 34(no decimal) How do I fix that Thanks I just did this and got 34.5 Sub lastrowdecimal() lastrow = 138 rrows = lastrow / 4 MsgBox rrows End Sub -- Don Guillett SalesAid Software dguillett1@austin.rr.com "pcor" <pcor@discussions.microsoft.com> wrote in message news:F21838BC-42AA-48A3-9B0C-D2139287A187@microsoft.com... >I have some VBA code as this: > rrows=lastrow/4 > > if lastrow is 138 then rrows should be 34.5 but I always get 34(no > decimal) >...

Currency and the number of decimal places
I have an application which has neen running for a number of years, firstly on Access2000 then XP and now on Access 2003. It uses many currency fields for invoicing , credit notes etc. Each field which is of currency type has the decimal property set to 2. Up until recently the ATB balanced fine but lately it has been a few cents out. The reason is that some amounts have been put in with 3 decimal places and some calculations (eg GST of 10% of $398.68 returning to the GST field a value of $39.868) returning 3 decimal places. I guess with the calculations, I can code to make sure only ...

Serial Numbers
We recently purchased a weekly newspaper, there are 4 MacIntosh computers running Microsoft Office 2004. The problem I am having is I had to rebuild one the other day and I don't know which product key to use. If you go to about Office 2004 you get this serial number of all number which don't match the product key. Is there a way to find out which serial number matches which product key. Any help would be greatly appreciated. No way to tell.... After reinstalling, look at the Product ID in the About window in any Office program. If you have used the same serial number twice, then t...

No decimals?
Hello! Is it possible to stop Money (2005) from using decimal places in the base currency? I am using a currency that uses only integers and no cents (because cents are almost worthless), and invoices amounts usually get some cents due to sales tax calculations, Is it possible to get rid of them? I find this very annoying since cents accumulate over several transactions, and end up with an slightly unreal balance... Thanks! Keiv Hi, It was possible in older version (pobably until 2001). You had to change the Windows's regional settings in the control panel before a new file creatio...

Decimal number to percentage formula (newbie question)
I've got a column full of numbers like 0.5, 1.0, etc. I need them to look like 0.500%. I figured out how to format the cells so that 0.5 looks like 0.500, but when I change the cell format to percentage, it makes 0.500 into 50.000%. So I figured out how to make a formula that divides 0.500 by 100 (=R1C6/100), resulting in 0.005, which I can format to a percentage and get 0.500%. Where I'm stumped is in applying that formula to the entire column. Instead of =R1C6/100, I want my formula to say =all rowsC6/100. How do I tell it {allrows}? Thanks for putting up with a newbie Ken Benson ...

Don't lose my decimals!
I have a int field and a decimal field (which however contains only numeric values) I need to divide this fields: SELECT field1/CONVERT(INT,field2) The operation is Ok, but I don't get decimal. I tried even SELECT CONVERT(FLOAT,field1/CONVERT(INT,field2)) but it's the same. How do I get decimals? And I want to get only two. Thanks. Luciano "Luciano (DOC)" <lucianodoc@luciano.doc> ha scritto nel messaggio news:4b9a83b3$0$1110$4fafbaef@reader2.news.tin.it... >I have a int field and a decimal field I mean a varchar field. L. Data typ...

Serial VS USB
My VB6 app looks at ports using the MSCOMM (MSCOMM32 ActiveX Control)component. I try to open a port and set parameters. Unfortunately, I do not know how to distinguish a serial port from a USB port. What test can I use to determine if the port is USB or Serial? Bee wrote: > My VB6 app looks at ports using the MSCOMM (MSCOMM32 ActiveX > Control)component. I try to open a port and set parameters. > Unfortunately, I do not know how to distinguish a serial port from > a USB port. What test can I use to determine if the port is USB or > Serial? If you can open it with...

European vs American decimals
I have transferred a chart with statistics from an American Website to my Dutch version of Excel 2003. All the statistics are stated in the American format (with a period as the decimal sign): example = 8.6 I am not able to make formulas because Excel doesn't seem to recognize the period (.) as a decimal sign. (all my equations get the answer 0) I would like to know how to change the period into a comma(the Dutch decimal sign), so that I can use the formula function. or I would like to know how to make Excel recognize the Amerian format to use the formula function. Thank you H...

Count digits before decimals and after decimals
Dear expert, Would like to count the digits before decimals and after decimals. For example, 111975.35 should be 6 digits before decimals and 2 digits after decimals 12456.25 should be 5 and 2 2478.24 should be 4 and 2 248.37 should be 3 and 2 Using LEN does not help. Can you help please? Hi, Why doesn't LEN help. try these =LEN(INT(A1)) and for the decimal portion =IF(ISERROR(FIND(".",A1)),0,LEN(A1)-FIND(".",A1)) -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while...

XML serialization(SOAP)
Hello! I'm reading in a book and it says the following about XML Serialization: - Support only limited data types - Is portable to other languages, notably Java Now to my question if it only support a limited data type how is that solved ? I mean if I use web services then all data is serialized using XML according to the SOAP protocol between the proxy(client) and the web service. I assume that this will cause problem if I use some data type that is not supported by the XML serialization. What kind of data types is not supported by the XML serialization ? //Tony ...

decimal separator?
Hi, I'm using web quiries to obtain data from web pages. Some of the sites use ',' as a desimal separator others use '.'. I'm from Finland so I'd like to use ',' as decimal separator. Is there a way to format those U.S.-format('.') numbers to Finnish-format(',') without changing the setting for the whole progmam/operating system?? Thank you, Jimmy format the cells where you will paste as text paste in the data format the cells a general do edit=>Replace Replace what . replace with , -- Regards, Tom Ogilvy Jimmy <jj_22_jj@yahoo...

Number Format
I have a system that records attribute data. An Engineer enters a specification range for the values and an integer value for the desired number of decimal places to display. I have the following formula in my report's record source Round([Act_Value], Nz([Dec_Place],0)) This works to limit the number of decimals, but doesn't "set" the display. For example [Act_value] = 0.5 [Dec_place] = 3 The above formula will diplay 0.5. I want it to display 05.00. Is there a way to do this? Any help will be appreciated. Use the format function Format(Round([Act_Value],...

How to use CSocket & Serialize in multithread network program?
Hi, all I'm writing a multithread program to transfer object data, I want to use CSocket & CSocketFile to serialize objects over network. On the server, I start a listening socket in main thread, when OnAccept() occurs, the main thread will create a sub thread that with a CSocket member, and the CSocket member will be accepted in main thread. I think the sub thread will take charge with the serialization of data before, but now it seems that the serialize code is run in the main thread, when serializing, the main thread can't accept new connection. How to use CSocket & ...

serializing element text using SOAP
I have generated a proxy class derived from System.Web.Services.Protocols.SoapHttpClientProtocol One of my classes is defined as [System.Xml.Serialization.SoapTypeAttribute("MyClass", "http://www.mycompany.com")] public class MyClass { public MyClass() { } public MyClass(String text) { this.Value = text; } [XmlText(typeof(string))] public string Value; } I wish for instances of this class to be serialized as <tns:MyClass>hello world</tns:MyClass> However it serializes as <tns:MyClass><Value xsi:type="xsd:string">hello worl...

serializing loops
Hi, I would appreciate any help regarding the following problem: Say I have a class A which has a member pointer to B, and class B has a member pointer to A. Now I have two instances of A and B, the member pointers of which point to each other. That is: class B; class A { public: B* Bptr; } class B { public: A* Aptr; } A a; B b; a.Bptr = b; b.Aptr = a; How should I implement the Serialize method for A and B? Another, perhaps slightly simpler question: Say I have class C which has a member pointer to class D, and there is more than one instance of C which points to the same instance o...

DOCTYPE with Xml Serialization
I have a class that serialize using the XmlSerializer. I am using several attributes for class members to control serialization process. One thing I cannot figure out how to do is how to add DOCTYPE attribute to the file. This XML file must use the doctype that refers to the DTD rather than an XSD. Could someone point out how to accomplish that using the attributes or by some other means? Thanks! Hi Vlad, Welcome to MSDN newsgroup. From your description, when you use the .NET XmlSerizliation to serizliaze some class instances out to xml stream, you want to also expose the DocType for ...

Qty Decimals
Hi Out There, Does anyone know if there is a way to set a part to 4 decimals, but to show 0 decimal places on the PO & SOP Screens and printouts? We would like to have the option of 4 decimals for Bills of Materials, but we don't want the orders and PO's to show 4.0000 because it forces the data entry to add a perios in order to make it a whole number. (We've been having issues with that) Thank you! You can do this with Modifier/VBA. If you don't find a better way and want to pursue this route let me know and I will help. ...

Protect your data base by Processor Serial Number Question
This code is used to know Your Computer Processor Number I think there are Missed reference or Module declaration section First Question Can any programmer Help me to complete this code and give me missed reference or module declaration section ==================== Dim objCPUSet As SWbemObjectSet Dim objWMINameSpace As SWbemServices Dim oCpu As SWbemObject Set objWMINameSpace = GetObject("winmgmts:") Set objCPUSet = objWMINameSpace.InstancesOf("Win32_Processor") For Each oCpu In objCPUSet Txt10 = oCpu.ProcessorID Exit For Next Set oCpu = Nothing Se...

POS 2009
Hi, I have a few clients and a an existing client that are interested in upgrading or buying Microsoft Dynamics POS 2009. However there is a fundamental problem as a feature that was available for RMS2.0 was now removed. In RMS2.0 you could use an assembly to include Serial Numbered Items and it would ask or search for the serial number during sell process in the POS. In Microsoft Dynamics POS 2009 assembly and kits and joint together as kits feature however Microsoft Dynamics POS 2009 - Kits cannot use Serial Numbered Items. For any companies that use Kits and serial numbers this is...

serialize object and store in a database
Hi! Is it common to serialized object and then store it in a database ? //Tony Hi, At least not directly because once the serialized object is stored in the db it would be difficult to query. Usually object properties are mapped to database columns using http://en.wikipedia.org/wiki/Object-relational_mapping technics, see in particular http://msdn.microsoft.com/en-us/library/bb386992.aspx for what ..NET provides out of the box. -- Patrice "Tony Johansson" <johansson.andersson@telia.com> a �crit dans le message de news:uFtHSVFyKHA.4492@TK2MS...