UnitConverter.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace LYFZ.WinAPI
  5. {
  6. public class UnitConverter
  7. {
  8. public const decimal K = 2.54M;
  9. /// <summary>
  10. /// 英寸转厘米
  11. /// </summary>
  12. /// <param name="inch"></param>
  13. /// <returns></returns>
  14. public static decimal InchToCm(decimal inch)
  15. {
  16. return inch * K;
  17. }
  18. /// <summary>
  19. /// 厘米转英寸
  20. /// </summary>
  21. /// <param name="cm"></param>
  22. /// <returns></returns>
  23. public static decimal CmToInch(decimal cm)
  24. {
  25. return cm / K;
  26. }
  27. /// <summary>
  28. /// (百分之一)英寸制,转毫米
  29. /// </summary>
  30. /// <returns></returns>
  31. public static int HundredthsInchToMM(decimal d)
  32. {
  33. return (int)Math.Round((d / 100.00M) * K * 10);
  34. }
  35. /// <summary>
  36. /// (百分之一)英寸制,转厘米
  37. /// </summary>
  38. public static decimal HundredthsInchToCM(decimal d)
  39. {
  40. return (d / 100.00M) * K;
  41. }
  42. /// <summary>
  43. /// 毫米,转(百分之一)英寸制
  44. /// </summary>
  45. /// <returns></returns>
  46. public static int MMToHundredthsInch(decimal d)
  47. {
  48. return (int)Math.Round((d / 10m / K) * 100.00M);
  49. }
  50. /// <summary>
  51. /// 厘米,转(百分之一)英寸制
  52. /// </summary>
  53. public static decimal CMToHundredthsInch(decimal d)
  54. {
  55. return (d / K) * 100.00M;
  56. }
  57. }
  58. }