fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. Console.WriteLine(Normalized(305));
  8. Console.WriteLine(Normalized(-305));
  9. Console.WriteLine(Normalized(0.0305));
  10. Console.WriteLine(Normalized(-0.0305));
  11. Console.WriteLine(Normalized(0.0));
  12. }
  13.  
  14. public static string Normalized(double num)
  15. {
  16. var ord = Ord(num);
  17. var mant = num / Math.Pow(10, ord);
  18. return string.Format("{0} * 10^{1}", mant, ord);
  19. }
  20.  
  21. public static int Ord(double num)
  22. {
  23. if(num == 0.0) { return 0; }
  24. return (int)Math.Floor(Math.Log10(Math.Abs(num)));
  25. }
  26. }
Success #stdin #stdout 0.04s 33920KB
stdin
Standard input is empty
stdout
3.05 * 10^2
-3.05 * 10^2
3.05 * 10^-2
-3.05 * 10^-2
0 * 10^0