XmlSerializer serializes float as 1E+07

Go To StackoverFlow.com

2

I have an ASMX client that receives an object in a response. This object contains properties and one of them is of type float.

Then I serialize response object and tranform it with XSLT to display it to users.

However, when value of that property is 10000000 then it's displayed as 1E+07 which is wrong.

When I change type of property in proxy class to double then it's again 10000000. But I am not sure if this is a solid solution.

I tried also XSLT format-number but XSLT 1.0 has not support for scientific notation.

2012-04-04 06:25
by jlp
I think the routine which does the serialising thinks that 10000000 is too many digits for a float (even though a float can hold 10000000 with no loss of precision). If changing to double works, I see no reason why you shouldn't just do that - Mr Lister 2012-04-04 06:39
Why is displaying 10000000 as 1E+07 wrong - David Heffernan 2012-04-04 07:24
@David Heffernan - ? Because a customer is unhappy with that - jlp 2012-04-04 10:57
@jlp That's different from it being wrong. But at least you've cleared it up - David Heffernan 2012-04-04 12:04


0

Change the property to decimal type. That is the approach with which you are guaranteed to see no silent loss of precision, and no scientific notation.

2012-04-04 07:11
by Jirka Hanika
Ads