Copied to clipboard

Flag this post as spam?

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


  • DonZalmrol 220 posts 833 karma points
    Nov 02, 2016 @ 15:59
    DonZalmrol
    0

    Math function does not work in partialview

    Hi all,

    I'm working on a website that requires to do some math equations. enter image description here As you can see I try to show the percentage for each shareholder by simply dividing the amount of shares they have by the total amount of shares.

    Now I'm trying to implement this by doing the following:

    @foreach(var item in selection)
        {
            percentage += (@item.numberOfShares / totalShares) * 100;
    
            <li>
                <div class="col-lg-4">
                    <p>@item.shareholderName</p>
                </div>
    
                <div class="col-lg-4">
                    <p>@item.numberOfShares.ToString("#,##0")</p>
                </div>
    
                <div class="col-lg-4">
                    <p>{@item.numberOfShares / @totalShares}</p>
                </div>
    
                <div class="solidline"></div>
            </li>
        }
    

    The code for "percentage" should be on the sport of the <p>{@item.numberOfShares / @totalShares}</p>

    But that isn't working as it only shows 0. The code that is written there shows the values, but not the end value.

    Anyway that I can fix this?

    Thank you in advance!

    Laurens

  • DonZalmrol 220 posts 833 karma points
    Nov 02, 2016 @ 16:36
    DonZalmrol
    100

    Found it :)

    <p>@string.Format("{0}", Math.Round((((double)@item.numberOfShares/totalShares)*100), 3)) %</p>
    

    enter image description here

    Now to clean up my code a bit.

  • 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