优化Axis的数值Label的默认显示格式

This commit is contained in:
monitor1394
2023-02-10 13:23:38 +08:00
parent d6630ef5bf
commit 80d9087084
7 changed files with 69 additions and 65 deletions

View File

@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace XCharts.Runtime
{
@@ -41,5 +36,23 @@ namespace XCharts.Runtime
{
return a + (b - a) * Clamp01(t);
}
public static bool IsInteger(double value)
{
return Math.Abs(value % 1) <= (Double.Epsilon * 100);
}
public static int GetPrecision(double value)
{
if (IsInteger(value)) return 0;
int count = 1;
double intvalue = value * Mathf.Pow(10, count);
while (!IsInteger(intvalue) && count < 38)
{
count++;
intvalue = value * Mathf.Pow(10, count);
}
return count;
}
}
}