using System;
using UnityEngine;
namespace GFGGame
{
public class NumberUtil
{
public static string GetChiniseNumberText(int num)
{
int numInUnit = 0;
int numInTen = 0;
string strInUnit = "";
string strInTen = "";
if (num == 0)
{
return "零";
}
if (num <= 10)
{
return GameConst.CHINESE_NUMBER[num - 1];
}
else if (num < 20)
{
numInUnit = num - 10;
strInUnit = GameConst.CHINESE_NUMBER[numInUnit - 1];
return "十" + strInUnit;
}
else if (num < 100)
{
numInTen = Mathf.FloorToInt(num / 10);
strInTen = GameConst.CHINESE_NUMBER[numInTen - 1];
numInUnit = num % 10;
if (numInUnit == 0)
{
return strInTen + "十";
}
else
{
strInUnit = GameConst.CHINESE_NUMBER[numInUnit - 1];
return strInTen + "十" + strInUnit;
}
}
return "未知";
}
public static string GetOldChiniseNumberText(int num)
{
int numInUnit = 0;
int numInTen = 0;
string strInUnit = "";
string strInTen = "";
if (num == 0)
{
return "零";
}
if (num <= 10)
{
return GameConst.CHINESE_NUMBER_OLD[num - 1];
}
else if (num < 20)
{
numInUnit = num - 10;
strInUnit = GameConst.CHINESE_NUMBER_OLD[numInUnit - 1];
return "拾" + strInUnit;
}
else if (num < 100)
{
numInTen = Mathf.FloorToInt(num / 10);
strInTen = GameConst.CHINESE_NUMBER_OLD[numInTen - 1];
numInUnit = num % 10;
if (numInUnit == 0)
{
return strInTen + "拾";
}
else
{
strInUnit = GameConst.CHINESE_NUMBER_OLD[numInUnit - 1];
return strInTen + "拾" + strInUnit;
}
}
return "未知";
}
public static string GetChiniseNumberWeekText(int num)
{
if (num >= 0 && num < GameConst.CHINESE_NUMBER.Length)
{
return GameConst.CHINESE_WEEK_NUMBER[num];
}
return "未知";
}
public static string ChangeNumberUnit(int num, int unit = 10000)
{
int count = num / unit;
if (count > 0)
{
return string.Format("{0}万", count);
}
return num.ToString();
}
///
/// 计算折扣-- 一位小数向上取整
///
/// 原始的价格
/// 现在的价格
///
public static string CalculateDiscount(double originalPrice, double discountedPrice)
{
double discountRate = discountedPrice / originalPrice;
double doubleNum = Math.Ceiling(discountRate * 100) / 10;
var roundedNumStr = doubleNum.ToString("0.0");
return roundedNumStr;
}
}
}