Wie kann ich eine Zahl in wissenschaftliche Notation umwandeln und den Exponenten erhalten? Zum Beispiel, wenn ich 23582 habe und es in 2,3582 x 10^4 umwandeln will und dann die '4' bekommen soll, was ist die Reihenfolge der Zahl? (Ich bin mit C#)Nummer in wissenschaftliche Notation konvertieren und Exponent erhalten
Antwort
Beachten Sie, dass das Ergebnis für den Fall negativ sein kann die Zahl weniger als 1 so verwenden wir Math.Floor
, dass zu behandeln:
int exponent = num == 0 ? 0 : (int)Math.Floor((Math.Log10(Math.Abs(num))));
' Math.Abs (num) 'innerhalb des Logarithmus; Vergessen Sie nicht 'num == 0' Fall –
@DmitryBychenko Danke, dass Sie darauf hingewiesen haben. – user3185569
Verwenden Sie einfach Logarithmus:
int exponent = value == 0
? 0 // special case: technically it should be -infinity
: (int) Math.Floor(Math.Log10(Math.Abs(value)));
I glaube nicht, dass dies Nummern behandelt, die kleiner als 1 sind. zB '0.2' – user3185569
@ user3185569: du hast recht; 'Math.Floor' oder ähnlich ist erforderlich –
Sie können die unten Notation,
int number = 23582;
Console.WriteLine(number.ToString("G2", CultureInfo.InvariantCulture));
Ausgang ist,
2.4E+04
- 1. Python; wissenschaftliche Notation String zu Nummer
- 2. wissenschaftliche Notation in Dezimal konvertieren in Bash
- 3. number_format() schlägt fehl, wissenschaftliche Notation zu konvertieren
- 4. Wissenschaftliche Notation Umwandlung - Schema
- 5. Wissenschaftliche Notation Farbbalken in Matplotlib
- 6. So erhalten Sie Exponent der wissenschaftlichen Notation in Matlab
- 7. Matlab Matrix wissenschaftliche Notation
- 8. R wissenschaftliche Notation in Plots
- 9. Lese wissenschaftliche Notation in C
- 10. wissenschaftliche Notation Abstraktion in Java
- 11. wissenschaftliche Schreibweise konvertieren mit php
- 12. Java DecimalFormat Wissenschaftliche Notation Frage
- 13. Wird wissenschaftliche Notation als int oder float interpretiert?
- 14. mongoexport Rückkehr wissenschaftliche (exponentiell) Notation
- 15. UIStepper.value wird die wissenschaftliche Notation
- 16. Wissenschaftliche Notation für ipywidgets slider
- 17. Java: Konvertieren Sie die wissenschaftliche Notation regelmäßig int
- 18. Verwenden Sie nur bei Bedarf wissenschaftliche Notation
- 19. BigDecimal hat wissenschaftliche Notation in Soap-Nachricht
- 20. Nutzung wissenschaftliche Notation mit XTABLE in R
- 21. Konvertieren der Nummer in wissenschaftlicher Notation in int
- 22. Disable wissenschaftliche Notation auf Achsen mit Bokeh
- 23. Matplotlib; Teilkräfte von zehn; Wissenschaftliche Notation
- 24. Wie konvertiert man positive oder negative wissenschaftliche Notation in C#?
- 25. sortieren numerische Spalte basierend auf absoluten Werten und wissenschaftliche Notation
- 26. Vermeidet die wissenschaftliche Notation von Excel beim Analysieren mit Pandas
- 27. Wie kann man die wissenschaftliche Notation in R verhindern?
- 28. Format BigDecimal ohne wissenschaftliche Notation mit voller Genauigkeit
- 29. readr: Schalte die wissenschaftliche Notation in write_csv aus
- 30. Vermeiden Sie die wissenschaftliche Notation in der Schnittfunktion in R
Dies ist die [log] (https://msdn.microsoft.com/en-us/library/system.math.log10 (v = vs.110) nur nehmen. aspx) (Basis 10) der Nummer. –
Wie wäre es mit dem ersten Lesen: https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx und kombinieren Sie es mit "string.Split" und "int.Parse" –