473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

length of decimal expansion

How do I go about writing a code to determine how many digits are in a decimal expansion of any given number?
I have entered the
cin >> N;
so that the user enters any number, but how do I calculate the number of digits they enter?
Oct 31 '08 #1
2 1685
If you want the number of digits AFTER the decimal there are countless ways to find them. This a random one I thought up:
Expand|Select|Wrap|Line Numbers
  1. Spoonfeeding code removed
If you want the number of digits BEFORE the decimal there are even more ways, like:
Expand|Select|Wrap|Line Numbers
  1. Spoonfeeding code removed
The integer i represents in both cases the number of digits.
Oct 31 '08 #2
donbock
2,426 Expert 2GB
You could input a string and later convert the string into a number. It should be straightforward to convert a string into a number. Finding the length of a string is trivial.

Don't count leading and trailing whitespace as decimal digits.
Don't count the decimal point as a decimal digit.
Oct 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
10
by: Clay_Culver | last post by:
I have heard that it is possible to use classes + template magic to make standalone functions (or maybe just a functor which acts like a function) which can accept variable length arguments without...
1
by: narenmehta | last post by:
I need to increase the value of a Decimal(4) to Decimal(10) I tried the following and it doesnt work. ALTER TABLE xyz ALTER COLUMN PAGE SET DATA TYPE DECIMAL(10);
1
by: Guadala Harry | last post by:
What do to about conversion to decimal type when blank is allowed? The situation is this. In the UI there is a textbox into which users can enter a value which is supposed to be a dollar amount....
3
by: Joe | last post by:
Hi, When I get the length of a string I expect to get an integer back. I getting back &H6 for both intVar1 and intVar2 from the following code: Dim strVar As String Dim intVar1 As Integer Dim...
0
by: kurt sune | last post by:
I have 2 attributes in a database table, both decimal with scale = 0, length 2 and 5. How do I best do a property in VB for them? I would like fixed length decimal. The 2 attributes in the...
7
by: Stefantastisk | last post by:
Hey there, Anyone knows a clever method for knowing the length of the digit after a decimal point in a standard C# decimal value, WITHOUT use of any string formatting. Example: 5231,12231 <-...
3
by: mohaaron | last post by:
Hello All, Does anyone know of a way to test a decimal for the number of places it has before and after the decimal? I need to do something like this. decimal value1 = 172.45; // If value1...
8
by: oh.i.love.spam | last post by:
I've been a procedural PHPer for a while now and I don't know why it has taken me so long to start the jump from procedural to OOP. I have a function that I would use for doing length...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.