-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
  • 704,970
  • 168
  • 1,303
  • 1,425
Ali Sajid
  • 3,576
  • 5
  • 17
  • 32

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
  • 121,762
  • 30
  • 236
  • 257
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,571
  • 1
  • 12
  • 28