C#到Lambda - 计算小数位数/第一个有效小数

CMH*_*CMH 5 c# lambda

出于好奇,下面会有一个等效的Lambda表达式吗?

...刚刚开始使用lambda,不熟悉zip等方法...

//Pass in a double and return the number of decimal places
//ie. 0.00009 should result in 5

//EDIT: Number of decimal places is good.
//However, what I really want is the position of the first non-zero digit 
//after the decimal place.

int count=0;
while ((int)double_in % 10 ==0)
{
double_in*=10;
count++;
}
Run Code Online (Sandbox Code Playgroud)

Ali*_*tad 7

 double1.ToString().SkipWhile(c => c!='.').Skip(1).Count()
Run Code Online (Sandbox Code Playgroud)

例如:

double double1 = 1.06696;
int count = double1.ToString().SkipWhile(c => c!='.').Skip(1).Count(); // count = 5;

double double2 = 16696;
int count2 = double2.ToString().SkipWhile(c => c!='.').Skip(1).Count(); // count = 0;
Run Code Online (Sandbox Code Playgroud)


And*_*rey 1

Math.Ceiling(-Math.Log(double_in, 10))
Run Code Online (Sandbox Code Playgroud)