Thread: how do you put a repeating decimal into c++

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    10

    how do you put a repeating decimal into c++

    How do you put a repeating decimal into c++ code for example 10.7333333 repeating the 3

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    There are fundamental limits on how many useful digits a number like that will contain anyway. So you can write 10.73333 for your purposes. If you really care, you can do some math like 10.4 + 1.0 / 3.0

  3. #3
    Registered User
    Join Date
    Feb 2015
    Posts
    10
    well i need to declare it in my code because the variable G = 32.2 ft/s^2 so i need to convert it to yds/s^2 and the number is 10.73 with the 3 repeating

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Yeah, divide by 3, like every other feet to yard conversion. The math will be correct.

  5. #5
    Registered User
    Join Date
    Feb 2015
    Posts
    10
    okay so im new to this will the require me to put #include <math.h>?

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    If you use functions from math.h, then yes you do. I don't know from the information that you gave me that you are actually using any math functions. You can divide without a library.

  7. #7
    Registered User
    Join Date
    Feb 2015
    Posts
    10
    what do you mean by math functions?

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The link in my previous post actually lists all of them. If you aren't using any, then no reason to include cmath exists.

  9. #9
    Registered User
    Join Date
    Feb 2015
    Posts
    10
    okay thank you so much!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert Decimal IP To Dotted Decimal Notation
    By MaSSaSLaYeR in forum C Programming
    Replies: 11
    Last Post: 11-16-2011, 06:18 PM
  2. Repeating a String in C
    By Keegan in forum C Programming
    Replies: 11
    Last Post: 11-16-2007, 11:46 AM
  3. repeating strings
    By h_howee in forum C++ Programming
    Replies: 9
    Last Post: 11-29-2006, 12:30 AM
  4. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM
  5. Help me for repeating decimal numbers plz
    By Supra in forum C Programming
    Replies: 3
    Last Post: 09-27-2001, 03:18 PM