PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] Why does Python's Decimal display some simple values as expontents and how can I prevent it?

 August 13, 2022     decimal, python     No comments   

Issue

I understand the value of exponents, but typically when displaying decimal values to an end user, it's easier for the layman to understand normal decimal values. When I perform the following, I'd rather the display value of the decimal be 50, instead of:

>>> Decimal('22679.6185') / Decimal('28.349523125') / 16
Decimal('5E+1')

Is this possible without quantizing or doing anything to modify the actual value? Also, why does it display a short value like this as an exponent and some longer values in their normal decimal form? Is this a product of division (irony intended)?


Solution

See: Significant figures in the decimal module (which admittedly tells you to use .quantize()). The main problem is that you must keep track of the number of significant digits manually.



Answered By - torek
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing