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 9203623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:30:49+00:00 2026-06-17T23:30:49+00:00

Possible Duplicate: Why doesn’t this division work in python? I have this and works

  • 0

Possible Duplicate:
Why doesn’t this division work in python?

I have this and works fine

def roi(stake, profit):
    your_roi = profit / stake * 100
    return your_roi

def final_roi():
    roi1 = roi(52, 7.5)
    print "%.2f"  % roi1

final_roi()

but if I change the profit number to an int (meaning both stake and profit will have an int value) e.g. 52, 7 it is giving the output of 0.00. what’s wrong there? I thought it had been formatted to be a float with the precision of two.

  • 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-17T23:30:50+00:00Added an answer on June 17, 2026 at 11:30 pm

    In python2.x, / does integer division (the result is an integer, truncated downward) if both arguments are of type integer. The “easy” fix is to put:

    from __future__ import division
    

    at the very top of your script, or to construct a float out of one of the arguments before dividing:

    your_roi = float(profit) / stake * 100
    

    Python also has an integer division operator (//), so you can still perform integer division if desired — even if you from __future__ import division

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

Sidebar

Related Questions

Possible Duplicate: Why doesn't this division work in python? A simple problem I'm having
Possible Duplicate: Strtotime() doesn’t work with dd/mm/YYYY format I have this variable which i
Possible Duplicate: Python: Adding element to list while iterating This doesn't seem to work,
Possible Duplicate: Why does this integer division yield 0? I have a C header
Possible Duplicate: getElementByClass().setAttribute doesn't work Why this: document.getElementsByClassName('cke_source').setAttribute('name', mymessage) Is returning: TypeError: Object #<NodeList>
Possible Duplicate: Variable doesn’t get returned from AJAX function I have this function: function
Possible Duplicate: If Javascript has first-class functions, why doesn’t this work? When I try
Possible Duplicate: If Javascript has first-class functions, why doesn’t this work? In Chrome, the
Possible Duplicate: Why doesn't this code produce the desired result? I have the code:
Possible Duplicate: JavaScript function aliasing doesn't seem to work Why doesn't this work? function

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.