-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShortenConversionTool.cs
More file actions
56 lines (50 loc) · 1.72 KB
/
ShortenConversionTool.cs
File metadata and controls
56 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Collections.Generic;
using UnityEngine;
namespace Demos.SOArchApproach.CodeBase.ScriptableObjectsFramework
{
public class ShortenConversionTool : ScriptableObject
{
public List<string> HashToStringCache;
public List<string> LenghToStringCache;
int GetShortHash(double value)
{
if(value < 1)
return 0;
int log = GetLenght(value);
int mod = ((log + 2) % 3) + 1;
int signs_after_comma = 3 - mod;
if((log - mod) > 0 && signs_after_comma > 0)
{
int tmp = (int)System.Math.Floor(value / System.Math.Pow(10, log - mod - signs_after_comma));
switch(signs_after_comma)
{
case 1:
return tmp * 100;
case 2:
return tmp * 10;
default:
return tmp;
}
}
else
return (int)System.Math.Floor(value / System.Math.Pow(10, log - mod));
}
public string GetLeft(double value)
{
return HashToStringCache[GetShortHash(value)];
}
int GetLenght(double value)
{
return value > 1 ? (int)System.Math.Floor(System.Math.Log10(value) + 1) : 1;
}
public string GetRight(double value)
{
int len = GetLenght(value);
return LenghToStringCache[len<LenghToStringCache.Count?len:LenghToStringCache.Count-1];
}
public string GetShort(double value)
{
return GetLeft(value) + GetRight(value);
}
}
}