Decimal


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Decimal

  1. #1
    Dean Guest

    Decimal


    What would be the coding to specify floats to be to 2 decimal places??

  2. #2
    Yuri Guest

    Re: Decimal


    Dean,
    float occupies 4 bytes and it's storage depends on platform,
    you can only specify conversion of float to string with desirable format.


    "Dean" <dbruce11@yahoo.com> wrote:
    >
    >What would be the coding to specify floats to be to 2 decimal places??



  3. #3
    Dean Guest

    Re: Decimal


    Yeah, but I tried to use setprecision and I tried to use printf but neither
    works properly. Do you know the actual coding as to how to specify just
    2 decimal places?

    "Yuri" <putivsky@home.com> wrote:
    >
    >Dean,
    >float occupies 4 bytes and it's storage depends on platform,
    >you can only specify conversion of float to string with desirable format.
    >
    >
    >"Dean" <dbruce11@yahoo.com> wrote:
    >>
    >>What would be the coding to specify floats to be to 2 decimal places??

    >



  4. #4
    Yuri Guest

    Re: Decimal


    Try

    float ft;
    // assign ft here;
    char buffer[32];
    sprintf(buffer, "%#10.2f", ft);

    "Dean" <dbruce11@yahoo.com> wrote:
    >
    >Yeah, but I tried to use setprecision and I tried to use printf but neither
    >works properly. Do you know the actual coding as to how to specify just
    >2 decimal places?
    >
    >"Yuri" <putivsky@home.com> wrote:
    >>
    >>Dean,
    >>float occupies 4 bytes and it's storage depends on platform,
    >>you can only specify conversion of float to string with desirable format.
    >>
    >>
    >>"Dean" <dbruce11@yahoo.com> wrote:
    >>>
    >>>What would be the coding to specify floats to be to 2 decimal places??

    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center