Skip to content

Instantly share code, notes, and snippets.

@wakeup5
Last active December 26, 2020 16:18
Show Gist options
  • Save wakeup5/ca493abaa93b2298106de8dd5db77438 to your computer and use it in GitHub Desktop.
Save wakeup5/ca493abaa93b2298106de8dd5db77438 to your computer and use it in GitHub Desktop.
BigInteger를 유닛 문자열로 변환하는 함수
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