12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace LYFZ.WinAPI
- {
- public class UnitConverter
- {
- public const decimal K = 2.54M;
- /// <summary>
- /// 英寸转厘米
- /// </summary>
- /// <param name="inch"></param>
- /// <returns></returns>
- public static decimal InchToCm(decimal inch)
- {
- return inch * K;
- }
- /// <summary>
- /// 厘米转英寸
- /// </summary>
- /// <param name="cm"></param>
- /// <returns></returns>
- public static decimal CmToInch(decimal cm)
- {
- return cm / K;
- }
- /// <summary>
- /// (百分之一)英寸制,转毫米
- /// </summary>
- /// <returns></returns>
- public static int HundredthsInchToMM(decimal d)
- {
- return (int)Math.Round((d / 100.00M) * K * 10);
- }
- /// <summary>
- /// (百分之一)英寸制,转厘米
- /// </summary>
- public static decimal HundredthsInchToCM(decimal d)
- {
- return (d / 100.00M) * K;
- }
- /// <summary>
- /// 毫米,转(百分之一)英寸制
- /// </summary>
- /// <returns></returns>
- public static int MMToHundredthsInch(decimal d)
- {
- return (int)Math.Round((d / 10m / K) * 100.00M);
- }
- /// <summary>
- /// 厘米,转(百分之一)英寸制
- /// </summary>
- public static decimal CMToHundredthsInch(decimal d)
- {
- return (d / K) * 100.00M;
- }
- }
- }
|