-3

I want to get the only that part which is before the point but I am unable to get it with every method. My value is 1.734565456765434E-06. I want to convert it into just 1

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ali Sajid
  • 3,964
  • 5
  • 18
  • 33

2 Answers2

2

Looks like you're trying to get the most significant digit of a number.

var n = 1.734565456765434E-06;
var exp = Math.Floor(Math.Log10(n)); // -6
var result = Math.Floor(n / Math.Pow(10, exp)); // 1

This can be generalized to this:

var n = 1.734565456765434E-06;
var nDigits = 1; // 1 significant digit
var exp = Math.Floor(Math.Log10(n));
var result = Math.Floor(n / Math.Pow(10, exp + (1 - nDigits)));
Community
  • 1
  • 1
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
0

If you are only interested in the first digit of your scientific representation, try this:

var number = 1.734565456765434E-06;
var numberString = number.ToString("E");
var firstDigitString = numberString.Substring(0, 1);
var firstDigit = int.Parse(firstDigitString);
abto
  • 1,583
  • 1
  • 12
  • 31