Skip to content

Magenaut

  • Home
  • Topics
    • Notes
    • Tutorial
    • Bug fixing
    • Extension
    • Server
  • Q&A
  • Privacy Policy
  • About

floating-point

How can I force division to be floating point? Division keeps rounding down to 0?

August 22, 2022 by Magenaut

I have two integer values a and b, but I need their ratio in floating point. I know that a < b and I want to calculate a / b, so if I use integer division I’ll always get 0 with a remainder of a.

Categories Python, Q&A Tags division, floating-point, integer, python, python-2.x Leave a comment

What is the best way to compare floats for almost-equality in Python?

August 22, 2022 by Magenaut

It’s well known that comparing floats for equality is a little fiddly due to rounding and precision issues.

Categories Python, Q&A Tags floating-point, python Leave a comment

How to use a decimal range() step value?

August 21, 2022 by Magenaut

Is there a way to step between 0 and 1 by 0.1?

Categories Python, Q&A Tags floating-point, python, range Leave a comment

Is floating point arbitrary precision available?

August 21, 2022 by Magenaut

Just for fun and because it was really easy, I’ve written a short program to generate Grafting numbers, but because of floating point precision issues it’s not finding some of the larger examples.

Categories Python, Q&A Tags floating-accuracy, floating-point, python Leave a comment

How to suppress scientific notation when printing float values?

August 21, 2022 by Magenaut

Here’s my code:

Categories Python, Q&A Tags floating-point, python Leave a comment

How to extract a floating number from a string

August 21, 2022 by Magenaut

I have a number of strings similar to Current Level: 13.4 db. and I would like to extract just the floating point number. I say floating and not decimal as it’s sometimes whole. Can RegEx do this or is there a better way? Answers: Thank you for visiting the Q&A section on Magenaut. Please note … Read more

Categories Python, Q&A Tags data-extraction, floating-point, python, regex Leave a comment

Formatting floats without trailing zeros

August 21, 2022 by Magenaut

How can I format a float so that it doesn’t contain trailing zeros? In other words, I want the resulting string to be as short as possible.

Categories Python, Q&A Tags floating-point, formatting, pretty-print, python Leave a comment

How to display a float with two decimal places?

August 21, 2022 by Magenaut

I have a function taking float arguments (generally integers or decimals with one significant digit), and I need to output the values in a string with two decimal places (5 → 5.00, 5.5 → 5.50, etc). How can I do this in Python?

Categories Python, Q&A Tags floating-point, python, string Leave a comment

Python JSON serialize a Decimal object

August 21, 2022 by Magenaut

I have a Decimal('3.9') as part of an object, and wish to encode this to a JSON string which should look like {'x': 3.9}. I don’t care about precision on the client side, so a float is fine.

Categories Python, Q&A Tags decimal, floating-point, json, python Leave a comment

Format / Suppress Scientific Notation from Pandas Aggregation Results

August 20, 2022 by Magenaut

How can one modify the format for the output from a groupby operation in pandas that produces scientific notation for very large numbers?

Categories Python, Q&A Tags floating-point, number-formatting, pandas, python, scientific-notation Leave a comment
Older posts
Page1 Page2 … Page5 Next →
  1. michealSmith07 on Is there a way to dynamically refresh the less command?August 21, 2022

    That is a very nice post. I like this post.

  2. anonymous on Fix libwacom9 dependency issue when upgrade DebianJune 27, 2022

    saved my day!! Thanks for the help…

  3. sreedhar on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    Thanks its working

  4. saintnick on Fix libwacom9 dependency issue when upgrade DebianMay 10, 2022

    remove libwacom2 worked for me as well

  5. ranafoul on Fix libwacom9 dependency issue when upgrade DebianApril 22, 2022

    apt remove libwacom2 helped on kali 2022.01. gr8

.net ajax asp.net asp.net-core asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-web-api bash c# command-line css custom-post-types custom-taxonomy dataframe dictionary django entity-framework functions gridview html iis javascript jquery json linux list matplotlib numpy pandas php plugin-development plugins posts python python-2.7 python-3.x security shell shell-script sql string vb.net webforms wp-query

© 2026 Magenaut • Built with GeneratePress