【Unity】指定した精度の数値に切り上げる

DEVELOP, Unity

public static double ToRoundUp(double dValue, int iDigits)
{
    double dCoef = System.Math.Pow(10, iDigits);
 
    return dValue > 0 ? System.Math.Ceiling(dValue * dCoef) / dCoef:
        System.Math.Floor  (dValue * dCoef) / dCoef;
}
 
public static double ToRoundDown(double dValue, int iDigits)
{
    double dCoef = System.Math.Pow(10, iDigits);
 
    return dValue > 0 ? System.Math.Floor  (dValue * dCoef) / dCoef:
        System.Math.Ceiling(dValue * dCoef) / dCoef;
}

Posted by kazupon