Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do you "cut off" a decimal?
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Silent Avenger




PostPosted: 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
Sponsor
sponsor
[Gandalf]




PostPosted: Thu Nov 30, 2006 12:40 am   Post subject: (No subject)

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




PostPosted: 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_




PostPosted: 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




PostPosted: 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




PostPosted: Thu Nov 30, 2006 5:31 pm   Post subject: (No subject)

Wow thanks for all the help everyone!
wtd




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
[Gandalf]




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: