코드
using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using UnityEngine;
public class BigCountTest : MonoBehaviour
{
public int viewcnt;//원하는 단위까지 표현
private string[] formatnumberarray = new string[]
{"","만","억","조","경","해","자","양","가","구","간" };
private string GetintText(int viewcnt=0)
{
int placeN = 4;
BigInteger value = myint;
List<int> numberList = new List<int>();
int p = (int)Mathf.Pow(10, placeN);
do
{
numberList.Add((int)(value % p));
value /= p;
} while (value>=1);
string retstr="";
if (viewcnt != 0)
{
viewcnt = Mathf.Max(0, numberList.Count - viewcnt);
}
for (int index = viewcnt; index < numberList.Count; index++)
{
retstr = numberList[index] + formatnumberarray[index] + retstr;
}
return retstr;
}
public string txt_display;
BigInteger myint;
// Start is called before the first frame update
void Start()
{
myint = 123456548;
string encodedNumber = GetintText();
Debug.Log("Encoded number: " + encodedNumber);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Y))
{
txt_display = GetintText();
}
if (Input.GetKeyDown(KeyCode.U))
{
txt_display = GetintText(viewcnt);
}
if (Input.GetKeyDown(KeyCode.T))
{
myint += myint;
}
}
}
댓글 없음:
댓글 쓰기