Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sundance 12 posts 52 karma points
    Jul 07, 2015 @ 21:22
    Sundance
    0

    Converting strings to int or decimals

    I'm using Umbraco 7 and the only place in my script that's getting an error is when I try to convert a string to an int or decimal.

    var price = home.price.AsInt(); or int price = home.price.AsInt();

    It will work fine without the AsInt() and take out all the math. There is a value in for the price for each node.

    This is in a partial view macro.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 07, 2015 @ 21:23
    Jeavon Leopold
    0

    Hello, what is the definition of "home"?

  • Sundance 12 posts 52 karma points
    Jul 07, 2015 @ 21:26
    Sundance
    0

    @helper displayHomes(dynamic homes) { if (homes.Any()) { foreach (var home in homes.OrderBy("price")) {
    var price = home.price.AsInt();

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 07, 2015 @ 21:31
    Jeavon Leopold
    101

    Ok, as it's dynamic you will need to cast it, e.g.

                    string priceString = (string)CurrentPage.price;                       
                    int price = priceString.AsInt();
    

    Are you sure that price isn't already a int, then you could cast it directly, e.g.

                    int price = (int)CurrentPage.price;                       
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies