栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

Unity3D--大额数值单位转换

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity3D--大额数值单位转换

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Numdispose("45555555207"));
            string[] symbol = {"个", "千", "百万", "十亿", "万亿" };
            Console.WriteLine(NumUnit(45555555207, symbol));
            Console.WriteLine(FormatNum(45555555207, 3));
            Console.ReadKey();
        }

        /// 
        /// 数字换算
        /// 
        /// 
        /// 
        public static string Numdispose(string num)
        {
            string[] symbol = { "K", "M", "B", "T", "aa", "ab", "ac", "ad" };

            string str1 = string.Empty;

            string str2 = string.Empty;

            if (num.Length > 6)
            {
                int a = (num.Length - 6) / 3;

                str1 = num.Substring(0, (num.Length - (3 * (a + 1))));

                int b = num.Length - (3 * (a + 1));

                str2 = num[b].ToString();

                if (int.Parse(str2) >= 5) str1 = (int.Parse(str1) + 1).ToString();

                if (str1.Length > 3) return str1.Insert(str1.Length - 3, ",") + symbol[a];

                return str1 + symbol[a];
            }
            if (num.Length > 3 && num.Length < 7)
            {
                return num.Insert(num.Length - 3, ",");
            }
            return num;
        }


        public static string NumUnit(double num, string[] unitArray)
        {
            double tempNum = num;
            if (tempNum < 10000)
            {
                return num.ToString("0");
            }

            int unitIndex = 0;
            while (tempNum / 10000 / 100 >= 1)
            {
                unitIndex++;
                if (unitIndex >= unitArray.Length)
                {
                    unitIndex = unitArray.Length - 1;
                    break;
                }
                tempNum /= 100;
            }
            return (tempNum / 10000).ToString("0.00") + unitArray[unitIndex];
        }

        /// 
        /// 数值转换 效果最好
        /// 
        /// 数值
        /// 保留小数点数
        /// 
        public static string FormatNum(decimal coin, int fixNum)
        {
            string textTemp = string.Empty;
            string text3 = "f" + fixNum.ToString();
            if (coin >= 100000000000000000000000000m)
            {
                textTemp = (coin / 100000000000000000000000000m).ToString(text3) + "ae";
            }
            else if (coin >= 1000000000000000000000000m)
            {
                textTemp = (coin / 1000000000000000000000000m).ToString(text3) + "ad";
            }
            else if (coin >= 1000000000000000000000m)
            {
                textTemp = (coin / 1000000000000000000000m).ToString(text3) + "ac";
            }
            else if (coin >= new decimal(1000000000000000000L))
            {
                textTemp = (coin / new decimal(1000000000000000000L)).ToString(text3) + "ab";
            }
            else if (coin >= new decimal(1000000000000000L))
            {
                textTemp = (coin / new decimal(1000000000000000L)).ToString(text3) + "aa";
            }
            else if (coin >= new decimal(1000000000000L))
            {
                textTemp = (coin / new decimal(1000000000000L)).ToString(text3) + "t";
            }
            else if (coin >= 1000000000m)
            {
                textTemp = (coin / 1000000000m).ToString(text3) + "b";
            }
            else if (coin >= 1000000m)
            {
                textTemp = (coin / 1000000m).ToString(text3) + "m";
            }
            else if (coin >= 1000m)
            {
                textTemp = (coin / 1000m).ToString(text3) + "k";
            }
            else
            {
                textTemp = coin.ToString("0");
            }

            return textTemp;
        }
    }
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/900527.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号