none
Numeric values in scientific (exponential) format RRS feed

  • Question

  • Dear all,

    I've a question about numeric values in scientific format in the dataset. Today, I got a dataset from database. a cell's value is 146264651.972237, but when I bound the web control GridView by dataset, all the values in the specific column are formated scientific format such as 1.462647E+08. So could I do something to convert to normal format and how to do it.

    PS: I try to fill the {0:d} in the DataFormatString in the Boundfield of the GridView, but nothing happed. :-(

    Thanks & regards!

    Radeon Ling

    Tuesday, August 24, 2010 9:35 AM

Answers

  • Per http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx, "d" is supported by integer types only. 

    You can try this instead: {0:0.#######}

    You'll need to decide the max number of decimal places you want after the decimal point and repeat the # accordingly.  To ensure right-fill with zeros, substitute 0 for #.  (Note that the range for the double-precision floating point exponent can be a quite large magnitude negative number, so in theory you could need hundreds of decimal places.  Hence the advantage of the scientific notation.)

    (Note:  Be sure to match the column data type with your database.  If your database column is DECIMAL, use System.Decimal -- not Single or Double float -- to avoid rounding problems.  Note that were you to use System.Decimal, the default formatting is not scientific notation so you would just get what you wanted.)

     

    • Marked as answer by liurong luo Thursday, August 26, 2010 9:45 AM
    Wednesday, August 25, 2010 12:56 AM