将价格格式从十进制更改为int [英] To change the format of price from decimal to int

查看:84
本文介绍了将价格格式从十进制更改为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在我的网站上显示价格的整数值(1900),然后删除十进制值(1900.00)

在Bussinesslocic中,我有一个cs文件,其中写入了以下内容,我需要帮助,以便将小数的格式更改为int.

I want to just display the integer value of price (1900) on my website and remove the decimal value (1900.00)

In Bussinesslocic i have a cs file where the following things are written i need help so that the format of decimal to be changed to int .

protected static string GetCurrencyString(decimal amount)
      {
          bool showCurrency = true;
          var targetCurrency = NopContext.Current.WorkingCurrency;
          return GetCurrencyString(amount, showCurrency, targetCurrency);
      }

      /// <summary>
      /// Gets currency string
      /// </summary>
      /// <param name="amount">Amount</param>
      /// <param name="showCurrency">A value indicating whether to show a currency</param>
      /// <param name="targetCurrency">Target currency</param>
      /// <returns>Currency string without exchange rate</returns>
      protected static string GetCurrencyString(decimal amount,
          bool showCurrency, Currency targetCurrency)
      {
          string result = string.Empty;
          if (!String.IsNullOrEmpty(targetCurrency.CustomFormatting))
          {
              result = amount.ToString(targetCurrency.CustomFormatting);
          }
          else
          {
              //if (!String.IsNullOrEmpty(targetCurrency.DisplayLocale))
              //{
              //    result = amount.ToString("C", new CultureInfo(targetCurrency.DisplayLocale));
              //}
              //else
              //{
                  result = String.Format("{1} {0}", amount.ToString("N"), targetCurrency.CurrencyCode);
                  return result;
              //}
          }

          if (showCurrency && IoC.Resolve<icurrencyservice>().GetAllCurrencies().Count > 1)
              // result = String.Format("{0} ({1})", result, targetCurrency.CurrencyCode);

              result =  result;
          return result;
      }

      #endregion

      #region Methods

      #region Calculation methods

      /// <summary>
      /// Gets the final price
      /// </summary>
      /// <param name="productVariant">Product variant</param>
      /// <param name="includeDiscounts">A value indicating whether include discounts or not for final price computation</param>
      /// <returns>Final price</returns>
      public static decimal GetFinalPrice(ProductVariant productVariant,
          bool includeDiscounts)
      {
          var customer = NopContext.Current.User;
          return GetFinalPrice(productVariant, customer, includeDiscounts);
      }

      /// <summary>
      /// Gets the final price
      /// </summary>
      /// <param name="productVariant">Product variant</param>
      /// <param name="customer">The customer</param>
      /// <param name="includeDiscounts">A value indicating whether include discounts or not for final price computation</param>
      /// <returns>Final price</returns>
      public static decimal GetFinalPrice(ProductVariant productVariant, Customer customer,
          bool includeDiscounts)
      {
          return GetFinalPrice(productVariant, customer, decimal.Zero, includeDiscounts);
      }

      /// <summary>
      /// Gets the final price
      /// </summary>
      /// <param name="productVariant">Product variant</param>
      /// <param name="customer">The customer</param>
      /// <param name="additionalCharge">Additional charge</param>
      /// <param name="includeDiscounts">A value indicating whether include discounts or not for final price computation</param>
      /// <returns>Final price</returns>
      public static decimal GetFinalPrice(ProductVariant productVariant, Customer customer,
          decimal additionalCharge, bool includeDiscounts)
      {
          return GetFinalPrice(productVariant, customer, additionalCharge,
              includeDiscounts, 1);
      }

      /// <summary>
      /// Gets the final price
      /// </summary>
      /// <param name="productVariant">Product variant</param>
      /// <param name="customer">The customer</param>
      /// <param name="additionalCharge">Additional charge</param>
      /// <param name="includeDiscounts">A value indicating whether include discounts or not for final price computation</param>
      /// <param name="quantity">Shopping cart item quantity</param>
      /// <returns>Final price</returns>
      public static decimal GetFinalPrice(ProductVariant productVariant, Customer customer,
          decimal additionalCharge, bool includeDiscounts, int quantity)
      {
          decimal result = decimal.Zero;

          //initial price
          decimal initialPrice = productVariant.Price;

          //price by customer role
          decimal? cpcc = GetCustomPriceByCustomerRole(productVariant, customer);
          if (cpcc.HasValue)
          {
              initialPrice = cpcc.Value;
          }

          //tier prices
          if (productVariant.TierPrices.Count > 0)
          {</icurrencyservice>

推荐答案

您好,

请参见下面的链接.
可能会对您有帮助.

http://www.csharp-examples.net/string-format-double/ [ ^ ]

谢谢,
Viprat
Hello,

Please See the below link.
It might be help you.

http://www.csharp-examples.net/string-format-double/[^]

Thanks,
Viprat


可以使用拆分功能

1.将十进制值转换为字符串
2.用char''''分割它.
3.获取[0]索引字符串
4.将其转换为int


或者您可以使用这种方式

1.将十进制值乘以100,并保持其为int类型
2.然后使用100
取结果的mod 3.从第一个减去第二个值
4.现在将结果除以100

{
例如:252.56
1. 252.56 * 100 = 25256
2. 25256%100 = 56
3. 25256-56 = 25200
4. 25200/100 = 252
}
you can use split function

1. convert the decimal value to string
2. split it with char ''.''
3. get the [0] index string
4. convert it to int


or you can use this way

1. multiply the decimal value with 100 and keep it in int type
2. then take the mod of the result with 100
3. substract the 2nd value from the 1st
4. now divide the result by 100

{
ex-: 252.56
1. 252.56 * 100 = 25256
2. 25256 % 100 = 56
3. 25256 - 56 = 25200
4. 25200 / 100 = 252
}


这篇关于将价格格式从十进制更改为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆