package common.util;

import java.text.DecimalFormat;
import java.util.Random;

/**
 * 숫자 관련 Util
 * @apiNote 숫자 관련 Util
 * @since 2020-01-01
 * @author 청록비
 * @version 2020-01-31 
 */
public class NumberUtil {
	
    public static final char[] digits = {
        '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 
        'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 
        'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' ,
        'u' , 'v' , 'w' , 'x' , 'y' , 'z' , 'A' , 'B' , 'C' , 'D' , 
        'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 
        'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 
        'Y' , 'Z'
    };
    
    public static String numberToBase(long num, int radix) {
        
    	if(radix > digits.length) {
    		radix = 10;
    	}
    	
    	long mod = 0;
    	StringBuffer rtnValue = new StringBuffer();
    	
    	while(num > 0) {
    		mod = num % (long)radix;
    		num = num / radix;
    		
   			rtnValue.append(digits[(int)mod]);
    	}
    	
    	return rtnValue.reverse().toString();
    }
}

+ Recent posts