最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

C# 将长度转换为毫米的方法

网站源码admin8浏览0评论

C# 将长度转换为毫米的方法

C# 将长度转换为毫米并向上取整:

代码语言:javascript代码运行次数:0运行复制
public static int ToMillimeters(double value, string unit)//转为:毫米
{
    switch (unit)
    {
        case "angstrom": return Convert.ToInt32(Math.Ceiling(value * 1e-7)); // 埃
        case "centimeters": return Convert.ToInt32(Math.Ceiling(value * 10)); // 厘米
        case "decimeters": return Convert.ToInt32(Math.Ceiling(value * 100)); // 分米
        case "feet": return Convert.ToInt32(Math.Ceiling(value * 304.8)); // 英尺
        case "hundredths_inches": return Convert.ToInt32(Math.Ceiling(value * 0.254)); // 百分之一英寸
        case "inches": return Convert.ToInt32(Math.Ceiling(value * 25.4)); // 英寸
        case "kilometers": return Convert.ToInt32(Math.Ceiling(value * 1e6)); // 公里
        case "meters": return Convert.ToInt32(Math.Ceiling(value * 1e3)); // 米
        case "micrometer": return Convert.ToInt32(Math.Ceiling(value * 0.001)); // 微米
        case "miles": return Convert.ToInt32(Math.Ceiling(value * 1.609e6)); // 英里
        case "millimeters": return Convert.ToInt32(Math.Ceiling(value)); // 毫米
        case "mils": return Convert.ToInt32(Math.Ceiling(value * 0.0254)); // 丝
        case "nanometer": return Convert.ToInt32(Math.Ceiling(value * 1e-6)); // 纳米
        case "picometer": return Convert.ToInt32(Math.Ceiling(value * 1e-9)); // 皮米
        case "yards": return Convert.ToInt32(Math.Ceiling(value * 914.4)); // 码
        default: throw new Exception("未知单位:" + unit);
    }
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论