Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to get the number of digits

how to get the number of digits

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elmahdy
    wrote on last edited by
    #1

    how to get the number of digits after the decimal point ex : Input : 5.1234 Expected Output : 4 i wrote this code but there are wornings.. what is wrong here ?? double input; int x=input; // so x=the integeral part of input int y=input-x; // so y=the fractional part while(y>0) {count++; input*=10; x=input; y=input-x; } plz help me !! elmahdy

    D L 2 Replies Last reply
    0
    • E elmahdy

      how to get the number of digits after the decimal point ex : Input : 5.1234 Expected Output : 4 i wrote this code but there are wornings.. what is wrong here ?? double input; int x=input; // so x=the integeral part of input int y=input-x; // so y=the fractional part while(y>0) {count++; input*=10; x=input; y=input-x; } plz help me !! elmahdy

      D Offline
      D Offline
      Dor
      wrote on last edited by
      #2

      you won't get the fractional part in y because it is an int.

      1 Reply Last reply
      0
      • E elmahdy

        how to get the number of digits after the decimal point ex : Input : 5.1234 Expected Output : 4 i wrote this code but there are wornings.. what is wrong here ?? double input; int x=input; // so x=the integeral part of input int y=input-x; // so y=the fractional part while(y>0) {count++; input*=10; x=input; y=input-x; } plz help me !! elmahdy

        L Offline
        L Offline
        Larry J Siddens
        wrote on last edited by
        #3

        I'm guessing there are a lot of ways to do this. How about this! double input; int Num = static_cast< int >( input ); intput -= static_cast< double >( Num ); You should now just have the .XXXX Char szData[1024]; ssprintf( szData, "%f", &Input ); int iLengt = strlen( szData ) - 2; //For the zero & the '.' This can give you a start. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups