Solved

Storing Decimal values using Int

Posted on 2006-11-29
6
215 Views
Last Modified: 2010-04-15
I was wondering if its possible to use an integer to store a decimal value as is or would I have to calctulate the value and then use mod (%) to get the remainder and then store the the two values in seperate variables.

Thanks in advance

Peter Allsop
0
Comment
Question by:peterallsop
  • 3
  • 2
6 Comments
 

Author Comment

by:peterallsop
ID: 18038777
Note: Storing the values in sepperate variables makes it harder to do calculations, thats the reason why im asking
0
 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 18038850

It's possible.  Most anything is possible.  But the question becomes, "why would you want to"?


The Floating point hardware allows you to store most any value, to the precision limits available.  Decimal (integer) hardware allows you to only store integers.

If you need precision less than 1 (fractions) you should definitely use floating point variables.  float or doubles.  Trying to do this yourself is an exercise for computer science students, not serious programmers.


Good Luck,
Kent


0
 
LVL 86

Expert Comment

by:jkr
ID: 18038856
Integers store what the name indicates: Integers. If you need to use values that have decimal places, you better should think about using floating point types like 'float' or 'double' which will better suit your purpose.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:peterallsop
ID: 18038896
Thanks for the information. There wasnt a really a reason I wanted to store a decimal using an Integer it was just out of interest.

I use float alot as I mainly deal with decimal values but theres comes a point when I wonder if theres another way to do it.

Thanks for the help

Peter
0
 
LVL 45

Expert Comment

by:Kdo
ID: 18038943

If I rememeber meaningless trivia correctly, most floating point conforms to the IEEE 754 standard.  You might google up the RFC and read a part of it.  It will give you a pretty good idea of what you'd have to do the hard way.


Kent

0
 

Author Comment

by:peterallsop
ID: 18038984
I'll take a look at it.

Thanks again

Pete
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now