We are having issue with consuming the numeric data through odata service in c# code.

We have page metadata with numeric field and if the length of the number specified in that field goes beyond 6 then odata returns data in exponential format. So 60135752 is returned as 6.0135752E7.

When trying to read this data through c# code, I am getting error:

Cannot convert a primitive value to the expected type 'Edm.Decimal'.

Has anybody faced similar issue? Any help is appreciated.

Note: I have verified that package and database have the data in non-exponential format, it is only when I retrieve it through Odata, I am getting it in exponential format.


This is actually related to the CD API and the fact we use a FLOAT in Java instead of a DOUBLE (see here for details).

Using the CD API would give you the same result as the WebService. Unfortunately, the only way around this is to set your CM field to a string instead of a number field. You can use a XSD restriction in your schema definition to enforce that editors enter numbers only in this field.

Unfortunately, changing this is a breaking change - we could change this in Java to be a DOUBLE instead... but then all the existing code using FLOAT would break. We're planning to address this in the next release, but... with the caveat that it might break your existing code.

  • Thanks for the insight. I am just curious to know little bit more about "break your existing code". I guess, only place number fields are used will be impacted by this change. The problem is currently there and we are not able to request data from CD service if we go beyond the limit of 6 digits in number field. Is there something that I am missing or is there any other breakage expected because of this change? – Hiren Kaku Aug 6 '15 at 17:41
  • 1
    All code that anyone wrote up to today that uses the CD API to read a FLOAT will stop working because we would now return a DOUBLE, meaning that you can't upgrade without changing code. That's what I mean with a breaking change. – Nuno Linhares Aug 6 '15 at 18:31

@Hiren, Previously I have faced same type of issue when I am trying to convert exponential to double. Below is the approach I have taken.

//Convert your data into string first

string str = myData.ToString();

double d = double.Parse(str);

First convert it to string then you can convert to Decimal/Double what you want. It works for me, you can try this -

  • @Sayatan - The option given by you will not work in my case because when I am accessing page metadata my query is: <odata service client>.Pages.Expand("CustomMetas"); Here I don't have any option to do the conversion that is handled automatically for odata proxy. – Hiren Kaku Aug 5 '15 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.