Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8801711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:54:15+00:00 2026-06-14T00:54:15+00:00

so I’m having trouble figuring out where I should be implementing the type cast

  • 0

so I’m having trouble figuring out where I should be implementing the type cast for my code. I understand the purpose of type casting, but I just don’t get (or am over thinking) where exactly it should go for my given situation.

So I have a function. It’s going to take the input and print it out in hexadecimal form.

void PrintHex(int InNum)
{
cout << hex << setiosflags (ios_base::showbase) << InNum;
};

The thing is, it’s not going to be receiving an int as expected, but rather a float from a member function of my class.

float Sphere::CalcCircumference()
{
return (Pi * (Radius*2));
};

I need to type cast the float to an int to avoid a loss of precision. But exactly where do I do this? I get a feeling I might need to do it in the member function that determines the Circumference, returning the outcome in static form. But I’m not sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:54:17+00:00Added an answer on June 14, 2026 at 12:54 am

    Your question is confusing: you mentioned you do not want to lose precision, but casting a float to an int will cause the precision loss. E.g.,

    float i = 1.3;
    int j = (int)i; // j get the value 1
    

    I’m guessing you want to print the content of the float variable as an int, so you don’t lose any precision. If that is the case, here is the way:

    float i = 1.3;
    int j = *((int*)&i); // j get the int representation value of i
    

    I hope you understand the round-off error for float type. In computers, there is no such thing that represent, for example, 0.2 precisely. So floating point always has some small errors. But that’s out of the scope of this function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.