Firstly should i use decimal or double for currency?
Secondly how do i get the data type to 2 decimal places. It works fine if the number is 34.56 but when it ends in 0 i.e. 32.10 it knocks off the zero and displays 32.1.
Help please.
Printable View
Firstly should i use decimal or double for currency?
Secondly how do i get the data type to 2 decimal places. It works fine if the number is 34.56 but when it ends in 0 i.e. 32.10 it knocks off the zero and displays 32.1.
Help please.
MS says :
logically decimal numbers that end in 0 are left out.Quote:
The Deftype statements are not supported in Visual Basic .NET. Nor is the Currency data type. Instead, use the new Decimal data type, which can handle more digits on both sides of the decimal point, for all money variables and calculations. Decimal is also directly supported by the common language runtime.
take a look at the Format function. That is, if you want to convert the number to a string representation.... you can add a 0 to the end of it this way
does this happen to everyone here ,:confused: .Here what I did :
but when I hit enter, the zero at the end was omittedVB Code:
Dim des As Decimal = 1.050
So no comment :pVB Code:
Dim des As Decimal = 1.05
well that will ALWAYS happen! it has to:D
if you want to format it, you can. I dont think there is a way to save the zero if you are saving it in a numerical variable, like decimal. but you can convert that to string. Try something like this:
dim myDec as Decimal = 11.3
debug.writeline ( format ( myDec.tostring(), "#.#0") ) ' results in 11.30
that will make sure that the second digit will end with a 0
debug.writeline ( format ( "11.33", "#.#0") ) ' results in 11.33
you could add as many zero's as you like
format ( someString, "#.#00000000000000000") :D
this is vb6 btw,and I believe it works in vb.net the exact same way. Maybe there is an improved function in .NET to use instead of this one
sure that results in ' results in 11.30;) ????
after you process your decimal variable then convert it to string then add "0" at the end of the variable like so :
VB Code:
Dim des As Decimal = 1.05 des = des.ToString MsgBox(des & "0")
guess this is the only way to fool MS VS.NET .lol
aaah did you try what I said?!!Quote:
Originally posted by pirate
after you process your decimal variable then convert it to string then add "0" at the end of the variable like so :
VB Code:
Dim des As Decimal = 1.05 des = des.ToString MsgBox(des & "0")
guess this is the only way to fool MS VS.NET .lol
if you want to have the decimal place for 2 digits then you do something like that I said. :)
alright my bad. I didnt actually try this in vb until now. The function has changed a bit. You dont have to convert it to string:
Format (myDecimalVar, "#.#0") will do the work, no need to convert the decimal to string
Mr.Polite , you are using String assignment in a way or another ,
look at this :
VB Code:
'this is the Format Function Format( ByVal Expression As Object, Optional ByVal Style As string = "" ) As String 'we use it this way Format(mydecimal, “#.##”)
using this function will set and return string value. So there is none difference betwen the two ways;)
Thanks for your help guys but with option strict on format doesn't seem to work.
However you can do this
Dim a As Decimal
a = CType(34.5, Decimal)
Dim value As String = a.ToString("N")
Returns 34.50