Author |
Message |
Silent Avenger
|
Posted: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
[Gandalf]
|
Posted: Thu Nov 30, 2006 12:40 am Post subject: (No subject) |
|
|
You'll want to look into either rounding, or truncating. |
|
|
|
|
|
wtd
|
Posted: Thu Nov 30, 2006 1:58 am Post subject: (No subject) |
|
|
Understand why many languages call functions that do just this kind of thing "ceil" and "floor". |
|
|
|
|
|
Monstrosity_
|
Posted: 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. |
|
|
|
|
|
cool dude
|
Posted: Thu Nov 30, 2006 5:11 pm Post subject: (No 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. |
|
|
|
|
|
Silent Avenger
|
Posted: Thu Nov 30, 2006 5:31 pm Post subject: (No subject) |
|
|
Wow thanks for all the help everyone! |
|
|
|
|
|
wtd
|
Posted: 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. |
|
|
|
|
|
RGB255
|
Posted: Sat Dec 02, 2006 10:40 pm Post subject: (No subject) |
|
|
This could come in very hany in my final project. Btw what are floating point numbers? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
[Gandalf]
|
Posted: Sun Dec 03, 2006 12:33 am Post subject: (No 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. |
|
|
|
|
|
|