Convert currency to Int format

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 năm cách đây
Hello,

How to convert currency to Int or float format in _ProductTierPrices.cshtml? not the source file.

i.e. convert "$100.00" to "100.00"

Z
4 năm cách đây
Hi,

The Price field of the TierPriceModel is a string type. You will have to remove the currency sign and parse it to int or float.

Regards,
Stoyan
4 năm cách đây
Thank you Stoyan,

How can I do that?
I'm not good at programming.

Thanks
Z
4 năm cách đây
1.You need to add new field in TierPriceModel
public decimal PriceValue {get;set;}
2. I am not sure which nop version are you using? so you need to just set PriceValue = without formatting price.
or
you can change Price type to decimal and set without formatted price.
4 năm cách đây
zhugefs wrote:
.... in _ProductTierPrices.cshtml? not the source file...


If you just want to remove the "$", you can probably change

@tierPrice.Price

to

@tierPrice.Price.Replace("$","")



(Do you only want to do this for the Tier Pricing?  If you want to affect all rices that the customer sees, then use the 'Custom formatting' field in the Currency configuration)
4 năm cách đây
Want to do a calculation in _ProductTierPrices.cshtml, show percentage (10% OFF, 20% OFF...) instead of the price value.

It's 4.2 version, NoSource
4 năm cách đây
zhugefs wrote:
Want to do a calculation in _ProductTierPrices.cshtml, show percentage (10% OFF, 20% OFF...) instead of the price value.

It's 4.2 version, NoSource


In _ProductTierPrices.cshtml page we can't get the product original price. It should be requires to show percentage base calculation.

I think you need to modify ProductTemplate.Simple.cshtml page for using Product original price.
@await Html.PartialAsync("_ProductTierPrices", Model.TierPrices) replace with @await Html.PartialAsync("_ProductTierPrices", Model)

then make change in _ProductTierPrices.cshtml file according to use ProductDetailsModel model whole page lke Model.TirePrice in foreach loop etc..


Percentage Calculation should be

@foreach (var tierPrice in Model.TierPrices)
{
    var tirepriceStr = tierPrice.Price.Replace("$", "");
    var tirepriceValue = Convert.ToDecimal(tirepriceStr);
    var subtractedPrice = Convert.ToDecimal(Model.ProductPrice.PriceValue - tirepriceValue);
    var calulatedPercentage = (subtractedPrice / Model.ProductPrice.PriceValue) * 100;
    <td class="item-price">
        @*@tierPrice.Price*@
        @calulatedPercentage.ToString("0.##")% OFF
    </td>
}
4 năm cách đây
satyanam wrote:
Want to do a calculation in _ProductTierPrices.cshtml, show percentage (10% OFF, 20% OFF...) instead of the price value.

It's 4.2 version, NoSource

In _ProductTierPrices.cshtml page we can't get the product original price. It should be requires to show percentage base calculation.

I think you need to modify ProductTemplate.Simple.cshtml page for using Product original price.
@await Html.PartialAsync("_ProductTierPrices", Model.TierPrices) replace with @await Html.PartialAsync("_ProductTierPrices", Model)

then make change in _ProductTierPrices.cshtml file according to use ProductDetailsModel model whole page lke Model.TirePrice in foreach loop etc..


Percentage Calculation should be

@foreach (var tierPrice in Model.TierPrices)
{
    var tirepriceStr = tierPrice.Price.Replace("$", "");
    var tirepriceValue = Convert.ToDecimal(tirepriceStr);
    var subtractedPrice = Convert.ToDecimal(Model.ProductPrice.PriceValue - tirepriceValue);
    var calulatedPercentage = (subtractedPrice / Model.ProductPrice.PriceValue) * 100;
    <td class="item-price">
        @*@tierPrice.Price*@
        @calulatedPercentage.ToString("0.##")% OFF
    </td>
}



I try it, unfortunately not work, maybe I miss something.

But I use your calculation format, and add the first tierpirce[0] with the same value as the selling price, then do the calculation, works.

Thank you very much.
Z
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.