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
Post a Comment