web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Convert money to decimal

(0) ShareShare
ReportReport
Posted on by

Morning all

I'm trying to convert a money field to a decimal but i keep getting an error about unable to cast. I have tried it various ways with no joy. Any ideas

for (int index = 0; productPriceLevelList.Entities != null && index < productPriceLevelList.Entities.Count; index++)
{
Entity newProductPriceLevelEntity = new Entity("productpricelevel");
newProductPriceLevelEntity["pricelevelid"] = new EntityReference("pricelevel", newPriceLevel.Id);
newProductPriceLevelEntity["productid"] = productPriceLevelList.Entities[index]["productid"];
newProductPriceLevelEntity["productnumber"] = productPriceLevelList.Entities[index]["productnumber"];
newProductPriceLevelEntity["uomid"] = productPriceLevelList.Entities[index]["uomid"];
string prodidse = Convert.ToString(productPriceLevelList.Entities[index]["productnumber"]);
decimal currentvar = Convert.ToDecimal(productPriceLevelList.Entities[index]["amount"]);  

Kind regards

Dan

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Refer this:

    forums.asp.net/.../1900908.aspx

  • Community Member Profile Picture
    on at

    i had a look at that and tried this with no luck

    decimal currentvar = decimal.Parse(productPriceLevelList.Entities[index]["amount"]);

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at
    decimal currentvar = ((Money)productPriceLevelList.Entities[index]["amount"]).value;


    Try the above.

  • Guowei_Xu Profile Picture
    407 on at

    I think you may check the entity Contains the field of "amount", before you convert it ToDecimal.

    For example,

    if (productPriceLevelList.Entities[index].Contains("amount"){

               decimal currentvar = Convert.ToDecimal(productPriceLevelList.Entities[index]["amount"]);

               }

  • ashlega Profile Picture
    34,477 on at

    Hi Dan,

     just go with Bopalan's answer.. That attribute is of "Money" type. You can't convert directly to Decimal. First cast it to Money, then get the Value

  • clarkjoel547 Profile Picture
    10 on at

    Thanks and I loved this post so much.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans