CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: decimal

  1. #1
    Join Date
    Oct 1999
    Posts
    21

    decimal

    Hi )

    I've a value : 3.5463729
    But I want to keep only the value : 3.55

    Is there a function to round decimals

    Thanks !

    Duke :-)


  2. #2
    Join Date
    Mar 1999
    Location
    Utah
    Posts
    66

    Re: decimal

    try this

    float f = 3.5463729;
    f *= 100.0f;
    int i = (int)f;//truncate
    f = ((float)i) / 100.0f;

    //or combine to save typing

    f = ((float)((int)(f * 100))) /100.0f;



    not tested but it should work. The idea is to move the decimal right 2, truncate, the move the decimal back




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured