C# to Lambda - count decimal places / first significant decimal -


out of curiosity, there equivalent lambda expression following?

... started using lambda not familiar yet methods zip ...

//pass in double , return number of decimal places //ie. 0.00009 should result in 5  //edit: number of decimal places good. //however, want position of first non-zero digit  //after decimal place.  int count=0; while ((int)double_in % 10 ==0) { double_in*=10; count++; } 

 double1.tostring().skipwhile(c => c!='.').skip(1).count() 

for example:

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; 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -