Storing Decimal values using Int

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
peterallsopAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:

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
 
peterallsopAuthor Commented:
Note: Storing the values in sepperate variables makes it harder to do calculations, thats the reason why im asking
0
 
jkrCommented:
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
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

 
peterallsopAuthor Commented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:

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
 
peterallsopAuthor Commented:
I'll take a look at it.

Thanks again

Pete
0
All Courses

From novice to tech pro — start learning today.