Hi,

I about to write some code, that will, in the end, format some HTML.

To keep storage space down, the idea is to hold the number as an integer, and pick out the character that relates to the specific format when writing it. My problem however comes when trying to pick out the character.

The idea is to divide the number by a multiple of 10, and take the first number to the right of the decimal place, that way, if no formatting is t be applied, the integer can be 0, and each division will therefore also be 0, saving space in the database.

Can anybody help me with a way of finding the number to the left of the Decimal Place?

Thanks,

uniquestar

Hi,

you can use the following logic.

suppose the number is 123.567

take 2 integer variables say a and b and 2 float variables say c and d.

now c=123.567
a = c
this will store integer part in a.
now do d = c-a

so d will have .567
and a will have 123

to get digits from a.
divide a with 10 each time and the reminder will be the digit.

to get digits from d
multiply d with 10 and each time you will get one digit.

I hope this will solve your problem.

commented: You're a creative Genius, Brilliant Suggestion! +4

That's Brilliant logic, Thanks!

Hi,
If you have got the solution, can you please close this thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.