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
  TypeError: conversion from bytes to Decimal is not supported Skaperen 2 1,172 Aug-28-2023, 02:36 AM
Last Post: Skaperen
  unexpected decimal.InvalidOperation Skaperen 2 1,902 Dec-25-2021, 05:55 PM
Last Post: Skaperen
  TIOBE Index for October 2021 - Python programming language number 1! Yoriz 1 1,546 Oct-07-2021, 11:35 PM
Last Post: Larz60+
  limiting number of digits as words in a function Skaperen 0 1,443 Oct-01-2021, 12:08 AM
Last Post: Skaperen
  convert a string to a number Naheed 7 4,490 Apr-26-2021, 08:08 AM
Last Post: Naheed
  system-wide unique incrementing string or number Skaperen 11 4,124 Jul-08-2020, 08:10 PM
Last Post: Yoriz
  converting a number from bytes to float and back Skaperen 3 2,562 Nov-12-2019, 07:59 PM
Last Post: Skaperen
  Floating and decimal Sandeep2000 2 2,468 Aug-16-2019, 04:25 PM
Last Post: Nitram
  py.exe: printing ascii number 7 qrani 3 3,482 Aug-27-2018, 01:35 PM
Last Post: Axel_Erfurt
  multiplying integer to decimal ArnabRoyBatman 8 12,714 Jun-20-2017, 04:49 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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