2023년 4월 17일 월요일

Unity 에서 만,억,조,경,해 등등 큰숫자 표현

 

코드



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;
        }
    }
}







댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...