Results 1 to 11 of 11

Thread: Decimal or Double

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181

    Decimal or Double

    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.
    Wind and waves resolves all problems.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    MS says :
    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.
    logically decimal numbers that end in 0 are left out.

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    does this happen to everyone here , .Here what I did :
    VB Code:
    1. Dim des As Decimal = 1.050
    but when I hit enter, the zero at the end was omitted

    VB Code:
    1. Dim des As Decimal = 1.05
    So no comment

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    well that will ALWAYS happen! it has to
    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")

    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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    sure that results in ' results in 11.30 ????

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    after you process your decimal variable then convert it to string then add "0" at the end of the variable like so :

    VB Code:
    1. Dim des As Decimal = 1.05
    2.         des = des.ToString
    3.         MsgBox(des & "0")

    guess this is the only way to fool MS VS.NET .lol

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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:
    1. Dim des As Decimal = 1.05
    2.         des = des.ToString
    3.         MsgBox(des & "0")

    guess this is the only way to fool MS VS.NET .lol
    aaah did you try what I said?!!
    if you want to have the decimal place for 2 digits then you do something like that I said.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Mr.Polite , you are using String assignment in a way or another ,

    look at this :
    VB Code:
    1. 'this is the Format Function
    2. Format( ByVal Expression As Object, Optional ByVal Style As string = "" ) As String
    3.  
    4. 'we use it this way
    5.  Format(mydecimal, “#.##”)

    using this function will set and return string value. So there is none difference betwen the two ways

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    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
    Wind and waves resolves all problems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width