Re: Controlling number of decimal places

From: Lars-Inge Tønnessen [VJ# MVP] (http://emailme.larsinge.com)
Date: 02/25/05

  • Next message: BillHouse: "Re: How to Create HTTPS Connection From J#"
    Date: Fri, 25 Feb 2005 21:48:46 +0100
    
    

    Please use System.String.Format( "{0:#.00}", System.Convert.ToDecimal(
    value ) ) to format the number of digits.

    {0 = the parameter index. We only have 1 parameter so this will always be 0.
    # = the value, it does not matter how many digits.
    0 = represents a digit.

    Example:

    //double value = 1.2344567;
    double value = 111.2;

    String s_value = System.String.Format( "{0:#.00}",
    System.Convert.ToDecimal( value ) );

    System.Console.WriteLine( "The value is: " + s_value );

    output:
    The value is: 111.20

    Eg
    String s_value = System.String.Format( "{0:#.000}",
    System.Convert.ToDecimal( value ) );

    Will give:
    The value is: 111.200

    Regards,
    Lars-Inge Tønnessen


  • Next message: BillHouse: "Re: How to Create HTTPS Connection From J#"

    Relevant Pages

    • Re: Custom date format not working in ACC2003
      ... It forces the year to display as 4 digits in dates, ... setting the Format of the control won't rescue it. ... the date fields in reports always format ...
      (microsoft.public.access.reports)
    • Re: Price Data Formatting
      ... I'm loading into the application price data that has a format I do not know ... Since price data format is all dependent on the market selected (say IBM ... rounded/truncated to 2 digits following the decimal as well. ... Dim sStr As String ...
      (microsoft.public.vb.general.discussion)
    • Re: Format Problem
      ... I set the numberformat property to General and it still does ... for the long date format. ... for the month and date separator, and displays two digits for the year. ... Currency Displays a number according to the Windows regional ...
      (microsoft.public.excel.programming)
    • Re: Text formatted cells displaying numbers in scientific format
      ... It is just Excel trying to be helpful. ... When it 'sees' a large number it uses scientific format since ... I accept that Excel can't handle numbers greater than 15 digits and your ... string was 16 digits or more to be converted to a scientific value. ...
      (microsoft.public.excel)
    • Re: float limits
      ... So how does MS guarantee no rounding errors ... > be guaranteeing 14 digits. ... What you are missing is that the C standard imposes no requirements ... If you want to understand the actual format of Intel floating point ...
      (comp.lang.c)

    Loading