Last active
December 26, 2020 16:18
-
-
Save wakeup5/ca493abaa93b2298106de8dd5db77438 to your computer and use it in GitHub Desktop.
BigInteger를 유닛 문자열로 변환하는 함수
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Numerics; | |
using UnityEngine; | |
public static class UnitIntegerExtensions | |
{ | |
public static string ToUnitString(this BigInteger b) | |
{ | |
if (b < 1000) | |
{ | |
return b.ToString(); | |
} | |
var unitNumber = Mathf.FloorToInt((float)BigInteger.Log10(b)) / 3; | |
var significand = Mathf.FloorToInt((float)BigInteger.Divide(b, BigInteger.Pow(10, unitNumber * 3 - 2))) / 100f; | |
var unit = (char)('A' + unitNumber - 1); | |
return $"{significand:N2}{unit}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment