How change the standard form format of double.ToString();

double.tostring java
c# double tostring format
c format double to 2 decimal places
c tostring (format)
c# tostring format date
c# format double to 1 decimal place
c format double to 2 decimal places
c string format currency

the following code:

double number = 85047564288067.5
string numberString = number.toString("G3");

will print: 8.5E+13

which obviously is correct but is there a way for the toString() function to return numbers that are in standard form in the format: 8.5x10^13?

Just replace E with x10^:

string numberString = number.ToString("G3", CultureInfo.InvariantCulture)
                            .Replace("E", "x10^").Replace("+", "");

The ToString(String, IFormatProvider) method formats a Double value in a In some cases, Double values formatted with the "R" standard numeric format string do Equals(roundTripped17)); // If compiled to an application that targets anycpu or To convert the numeric values to strings, the example uses the formatting  Table 1. ToString (String, IFormatProvider) Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information. ToString (String) Converts the numeric value of this instance to its equivalent string representation, using the specified format.

If it's just for display purposes, then this should do the job.

    double number = 85047564288067.5;
    string numberString = number.ToString("G3").Replace("E+","x10^");

A standard numeric format string takes the form Axx , where: A is a single Some overloads of the ToString method of all numeric types. A standard numeric format string can be used to define the formatting of a numeric value in one of two ways: It can be passed to an overload of the ToString method that has a format parameter. The following example formats a numeric value as a currency string in the current culture (in this case, the en-US culture).

You can use it more effectively as follows

Extension Method

 public static class DoubleExtension
            public static string ToString10Th(this double p)
               return p.ToString("0.#E+0", CultureInfo.InvariantCulture).Replace("E-", "x10^-").Replace("E+", "x10^");            


    double number = 85047564288067.5;

Mathematics Questions, English – Placements, Experienced, Full Form, Game Double.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation. Exceptions: This method throws FormatException if format is invalid. Syntax: public override string ToString ();. Write six hundred forty-five million five hundred eighty-four thousand four hundred sixty-two in standard form. So let's tackle this piece by piece. So the first part we have six hundred and forty-five million. So let's think about that. So we have six hundred and forty-five. But it's not just six hundred forty-five.

Try with exponential notation. Maybe something like this:

double number = 85047564288067.5
string numberString = string.Format("{0:0.#E+00}", number);

Java Convert double to String example and examples of string to int, int to It is generally used if we have to display double value in textfield for GUI application because everything is double d=12.3;//floating literal is double by default; String s=String. toString(). The Double.toString() method also converts float to String. Java Double To String Without Exponential Scientific Notation. Nov 02, 2016 Core Java, Examples, Snippet, String comments . When dealing with numbers that are not whole, the type double is usually used for convenience because it is primitive and has good precision.

Convert double to string in Java using toString() method of Double wrapper class. 3. Java – double to string conversion using String.format() method StringBuffer sb = new StringBuffer(); //appending the double value to StringBuffer instance  The bindings on the Slider and TimePicker show the use of format specifications particular to double and TimeSpan data types. The StringFormat that displays the text from the Entry view demonstrates how to specify double quotation marks in the formatting string with the use of the " HTML entity.

The toString() method provides a canonical representation of a BigDecimal . For example, rounding the value 999.9 to three digits rounding up would be numerically This is generally the preferred way to convert a float or double into a A standard canonical string form of the BigDecimal is created as though by the  The Format specifier can be used to convert the number into the string in the form "-d.ddd..E+ddd" or "-d.ddd..e+ddd", where d represents any digits between 0 to 9 and the negative sign represents the negative number. At least one digit exists before the decimal point. After the decimal point the desired number of digits exist.

Standard Ed. 7 The Double class wraps a value of the primitive type double in an object. 754 floating-point "double format" bit layout, preserving Not-a-​Number (NaN) values. toString. public static String toString(double d). Returns a string then it is represented as the integer part of m, in decimal form with no leading  format style changes the output display format in the Command Window to the format specified by style. format, by itself, resets the output format to the default, which is the short, fixed-decimal format for floating-point notation and loose line spacing for all output lines. Numeric formats affect only how numbers appear in Command Window

  • On my German machine this returns 8,5x10^13 (mind the comma)
  • @marsze that's because the separator is different in your culture
  • @RuiJarimba Of course it is and that's why you have to take that into account!
  • @marsze my point is that the OP is concerned with the exponent part of the number/output, not with the decimal or thousands separator
  • @Adrian I just ran a test, it should be .Replace("E", "x10^") instead of .Replace("e", "x10^")
  • I should note that this wont work on negatives, another answer below covers negatives.
  • I don't know why this answer was downvoted, it seems to work fine - even with negatives. The output is the same as the accepted answer.
  • @RuiJarimba It does not work with negative exponents, that's the issue
  • @Adrian got it :)
  • This is not what the OP is asking for.... Your output is 8.505E+13, not 8.505x10^13