| | |
| | | return val.Replace(@"</r>", "\n"); |
| | | } |
| | | |
| | | public static double numto2Decimals(double value) |
| | | { |
| | | //为什么要value * 1000/10 这么写,特殊的数字会有问题,比如36.80000,会(int)(value * 100)被计算为3679 |
| | | //测试下只有30几点8000的才会这样 |
| | | return (int)(value * 1000 / 10) / 100.00; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 大数值转化 格式 最多两个小数 |
| | | /// 大数值转化 格式 最多两个小数 ,向下取整 |
| | | /// K -千,M -百萬,B-十億,T -萬億 |
| | | /// 不四舍五入,不用Math.Round,因为当玩家只有23.3456,但是Math.Round会显示23.35, 当购买价格为23.35时无法购买的 |
| | | /// </summary> |
| | | public static string ReplaceLargeNum(double num) |
| | | { |
| | |
| | | |
| | | if (num >= T) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / T).ToString("0.##"), Language.Get("L1070_0")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / T, 2), Language.Get("L1070_0")); |
| | | } |
| | | else if (num >= B) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / B).ToString("0.##"), Language.Get("L1070_1")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / B, 2), Language.Get("L1070_1")); |
| | | } |
| | | else if (num >= M) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / M).ToString("0.#"), Language.Get("L1070")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / M, 1), Language.Get("L1070")); |
| | | } |
| | | else if (num >= K) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / K).ToString("0.#"), Language.Get("L1071")); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / K, 1), Language.Get("L1071")); |
| | | } |
| | | else |
| | | { |
| | | return numto2Decimals(num).ToString("0.#"); |
| | | return FormatWithoutRounding(num, 1); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (num >= T) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / T).ToString("0.##"), "t"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / T, 2), "t"); |
| | | } |
| | | else if (num >= B) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / B).ToString("0.##"), "b"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / B, 2), "b"); |
| | | } |
| | | else if (num >= M) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / M).ToString("0.#"), "m"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / M, 1), "m"); |
| | | } |
| | | else if (num >= K) |
| | | { |
| | | return StringUtility.Contact(numto2Decimals(num / K).ToString("0.#"), "k"); |
| | | return StringUtility.Contact(FormatWithoutRounding(num / K, 1), "k"); |
| | | } |
| | | else |
| | | { |
| | | return numto2Decimals(num).ToString("0.#"); |
| | | return FormatWithoutRounding(num, 1); |
| | | } |
| | | } |
| | | |
| | | //根据小数位数直接截断不做四舍五入 |
| | | public static string FormatWithoutRounding(double value, int decimalPlaces) |
| | | { |
| | | double factor = Math.Pow(10, decimalPlaces); |
| | | double truncated = Math.Truncate(value * factor) / factor; |
| | | return truncated.ToString($"0.{new string('#', decimalPlaces)}"); |
| | | } |
| | | |
| | | |
| | | // 转化大数值带单位的显示,如果小于200000则显示原值,否则显示大数值 |
| | | public static string ReplaceLargeNumEx(double num) |
| | |
| | | } |
| | | |
| | | //显示数量, 格式n/m, 足够绿色不足红色 |
| | | public static string ShowUseMoney(int moneyType, long useCnt, TextColType engoughColor = TextColType.Green) |
| | | public static string ShowUseMoney(int moneyType, long useCnt, bool showLargeNum = false) |
| | | { |
| | | long cnt = GetMoneyCnt(moneyType); |
| | | return AppendColor(useCnt <= cnt ? engoughColor : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{ReplaceLargeNum(useCnt)}"); |
| | | if (showLargeNum) |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{useCnt}"); |
| | | else |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{cnt}/{useCnt}"); |
| | | } |
| | | |
| | | public static string ShowUseItem(PackType type, int itemId, long useCnt, TextColType engoughColor = TextColType.Green) |
| | | public static string ShowUseItem(PackType type, int itemId, long useCnt, bool showLargeNum = false) |
| | | { |
| | | long cnt = PackManager.Instance.GetItemCountByID(type, itemId); |
| | | return AppendColor(useCnt <= cnt ? engoughColor : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{ReplaceLargeNum(useCnt)}"); |
| | | if (showLargeNum) |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{ReplaceLargeNum(cnt)}/{useCnt}"); |
| | | else |
| | | return AppendColor(useCnt <= cnt ? TextColType.Green : TextColType.Red, $"{cnt}/{useCnt}"); |
| | | } |
| | | |
| | | |