Demonstration of c\

From , 3 Years ago, written in C#, viewed 52 times.
URL https://pastebin.vip/view/5ffaa9f5
  1. public class MathHelper
  2.     {
  3.         public static decimal Dot3(decimal d)
  4.         {
  5.             return decimal.Parse(String.Format("{0:0.###}", d));
  6.         }
  7.  
  8.         public static decimal Dot2(decimal d)
  9.         {
  10.             return decimal.Parse(String.Format("{0:0.##}", d));
  11.         }
  12.  
  13.         public static decimal Dot4(decimal d)
  14.         {
  15.             return decimal.Parse(String.Format("{0:0.####}", d));
  16.         }
  17.  
  18.         public static decimal Dot6(decimal d)
  19.         {
  20.             return decimal.Parse(String.Format("{0:0.######}", d));
  21.         }
  22.  
  23.         /// <summary>
  24.         /// 获取价格相差
  25.         /// </summary>
  26.         /// <param name="firstPrice">价格1</param>
  27.         /// <param name="sencondPrice">价格2</param>
  28.         /// <returns>价格差</returns>
  29.         public static decimal GetDiffPrice(decimal firstPrice, decimal sencondPrice)
  30.         {
  31.             return firstPrice - sencondPrice;
  32.         }
  33.  
  34.         /// <summary>
  35.         /// 获取价格差百分比
  36.         /// </summary>
  37.         /// <param name="firstPrice">价格1</param>
  38.         /// <param name="sencondPrice">价格2</param>
  39.         /// <returns>价格差百分比</returns>
  40.         public static decimal GetPercentDiffPrice(decimal firstPrice, decimal sencondPrice)
  41.         {
  42.             if (sencondPrice == 0)
  43.                 return 0;
  44.             return MathHelper.Dot2((GetDiffPrice(firstPrice, sencondPrice) / sencondPrice) * 100);
  45.         }
  46.  
  47.         /// <summary>
  48.         /// 将小数值按指定的小数位数截位
  49.         /// </summary>
  50.         /// <param name="value">要截位的小数</param>
  51.         /// <param name="length">小数位数,s大于等于0,小于等于28</param>
  52.         /// <returns></returns>
  53.         public static decimal ToFixed(decimal value, int length)
  54.         {        
  55.             decimal sp = Convert.ToDecimal(Math.Pow(10, length));
  56.             return Math.Truncate(value) + Math.Floor((value - Math.Truncate(value)) * sp) / sp;
  57.         }
  58.  
  59.         /// <summary>
  60.         /// 将小数值按指定的小数位数进位(大于0进位)
  61.         /// </summary>
  62.         /// <param name="value">要进位的小数</param>
  63.         /// <param name="length">小数位数,s大于等于0,小于等于28</param>
  64.         /// <returns></returns>
  65.         public static decimal ToCeiled(decimal value, int length)
  66.         {
  67.             decimal sp = Convert.ToDecimal(Math.Pow(10, length));
  68.             return Math.Ceiling(value * sp) / sp;
  69.         }
  70.     }
  71. //csharp/7022

Reply to "Demonstration of c\"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website