Computer Science Canada

How do you "cut off" a decimal?

Author:  Silent Avenger [ Wed Nov 29, 2006 9:33 pm ]
Post subject:  How do you "cut off" a decimal?

Okay I making a program where I input and output prices and I would like to know how to make the decimal go to only 2 places. I've already tried using the variable as a currency type but it still doesn't work.

Author:  [Gandalf] [ Thu Nov 30, 2006 12:40 am ]
Post subject: 

You'll want to look into either rounding, or truncating.

Author:  wtd [ Thu Nov 30, 2006 1:58 am ]
Post subject: 

Understand why many languages call functions that do just this kind of thing "ceil" and "floor".

Author:  Monstrosity_ [ Thu Nov 30, 2006 3:43 pm ]
Post subject:  Re: How do you "cut off" a decimal?

Silent Avenger wrote:
Okay I making a program where I input and output prices and I would like to know how to make the decimal go to only 2 places. I've already tried using the variable as a currency type but it still doesn't work.

The Currency just provides a different method of storage for your numbers, since you wouldn't use floating-point numbers things such as currency.
As for the decimal places, look into the FormatCurrency() function.

Author:  cool dude [ Thu Nov 30, 2006 5:11 pm ]
Post subject: 

you don't need currency. to round of to 2 decimal places use the format command and inside the brackets the name of the variable you want to round to 2 decimal places and "0.00"

Example

code:

    quotient = 20 / 26
    Text1.Text = Format(quotient, "0.00")


if you want to round to 3 decimal places you would add an extra 0. and so on.

Author:  Silent Avenger [ Thu Nov 30, 2006 5:31 pm ]
Post subject: 

Wow thanks for all the help everyone!

Author:  wtd [ Fri Dec 01, 2006 12:32 am ]
Post subject:  Re: How do you "cut off" a decimal?

Monstrosity_ wrote:
The Currency just provides a different method of storage for your numbers, since you wouldn't use floating-point numbers things such as currency.


Indeed. Never ever use floating point numbers for currency.

If you feel tempted to do so, just watch the movie Office Space.

Author:  RGB255 [ Sat Dec 02, 2006 10:40 pm ]
Post subject: 

This could come in very hany in my final project. Btw what are floating point numbers?

Author:  [Gandalf] [ Sun Dec 03, 2006 12:33 am ]
Post subject: 

Floating point numbers, as basically as you can get, are numbers with decimals, for example:
1.56
0.065
16342.6

You could have found this out from a simple Google/Wikipedia search.


: