Get number of digits before decimal point

前端 未结 25 1935
独厮守ぢ
独厮守ぢ 2020-12-28 11:53

I have a variable of decimal type and I want to check the number of digits before decimal point in it. What should I do? For example, 467.45 should

25条回答
  •  -上瘾入骨i
    2020-12-28 12:08

    Use modulo, i'm not a C# programmer, but I'm pretty sure this solution work:

    double i = 1;
    int numberOfDecimals = 0;
    
    
    while (varDouble % i != varDouble)
    {
    numberOfDecimals++;
    i*=10;
    }
    
    return numberOfDecimals;
    

提交回复
热议问题