Python Forum
number of digits in a decimal.Decimal number object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
number of digits in a decimal.Decimal number object
#1
given a decimal number (via args in a function, for example), i can find out how many digits it has with:
how_many_digits = len(str(a_decimal_number))-1
is there a better. more appropriate, way to do that, that i may have missed? i want to get the minimum precision i need to set to work with this decimal number in decimal. i may decide to use twice as many to cover extreme cases with multiplication and division.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  can a number preceed a line of code? Skaperen 4 445 May-09-2024, 02:50 AM
Last Post: Skaperen
  TypeError: conversion from bytes to Decimal is not supported Skaperen 2 1,253 Aug-28-2023, 02:36 AM
Last Post: Skaperen
  unexpected decimal.InvalidOperation Skaperen 2 1,963 Dec-25-2021, 05:55 PM
Last Post: Skaperen
  TIOBE Index for October 2021 - Python programming language number 1! Yoriz 1 1,592 Oct-07-2021, 11:35 PM
Last Post: Larz60+
  limiting number of digits as words in a function Skaperen 0 1,475 Oct-01-2021, 12:08 AM
Last Post: Skaperen
  convert a string to a number Naheed 7 4,616 Apr-26-2021, 08:08 AM
Last Post: Naheed
  system-wide unique incrementing string or number Skaperen 11 4,233 Jul-08-2020, 08:10 PM
Last Post: Yoriz
  converting a number from bytes to float and back Skaperen 3 2,627 Nov-12-2019, 07:59 PM
Last Post: Skaperen
  Floating and decimal Sandeep2000 2 2,555 Aug-16-2019, 04:25 PM
Last Post: Nitram
  py.exe: printing ascii number 7 qrani 3 3,533 Aug-27-2018, 01:35 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020