dcsimg
Results 1 to 10 of 10

Thread: VB Satoshi convert help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    26

    VB Satoshi convert help

    6.78845934253293e-05 = 0.00006788
    6.78845934253293e-06 = 0.00000678
    5.57578546610181e-07 = 0.00000055





    how do I make this change
    do you have a code that provides

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    640

    Re: VB Satoshi convert help

    Quote Originally Posted by sorgu View Post
    6.78845934253293e-05 = 0.00006788
    6.78845934253293e-06 = 0.00000678
    5.57578546610181e-07 = 0.00000055





    how do I make this change
    do you have a code that provides
    I found two ways:
    1. Store the numbers using the Decimal datatype or convert them to the Decimal datatype before displaying them.
    2. Put your numbers in between braces and add ".ToString("F20") where the "20" part means use 20 zeros.

    Examples:
    Code:
    Console.WriteLine(CDec(0.0000678845934253293))
    Console.WriteLine((0.0000678845934253293).ToString("F30"))

  3. #3
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    427

    Re: VB Satoshi convert help

    Funny I thought this was the VB6 and earlier forum.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim N As Double
        N = 6.78845934253293E-05
        N = Format(N, "0.00000000")
        MsgBox N
    End Sub

  4. #4
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    427

    Re: VB Satoshi convert help

    Double Post!

  5. #5
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    640

    Re: VB Satoshi convert help

    Quote Originally Posted by Steve Grant View Post
    Funny I thought this was the VB6 and earlier forum.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim N As Double
        N = 6.78845934253293E-05
        N = Format(N, "0.00000000")
        MsgBox N
    End Sub
    Oops, my mistake. My first example of converting to the Decimal data type still holds though. It works in vb6 too. (Except for writing to the console.)
    Last edited by Peter Swinkels; Jan 12th, 2019 at 07:37 AM. Reason: Added some info.

  6. #6
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    427

    Re: VB Satoshi convert help

    @Peter, actually no it doesn't. Try this;

    Private Sub Form_Load()
    Dim N As Double
    N = 6.78845934253293E-05
    'N = Format(N, "0.00000000")
    N = CDec(N)
    MsgBox N
    End Sub

  7. #7
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    427

    Re: VB Satoshi convert help

    @Peter, actually no it doesn't. Try this;

    Code:
    Private Sub Form_Load()
        Dim N As Double
        N = 6.78845934253293E-05
        'N = Format(N, "0.00000000")
        N = CDec(N)
        MsgBox N
    End Sub

  8. #8
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    640

    Re: VB Satoshi convert help

    Quote Originally Posted by Steve Grant View Post
    @Peter, actually no it doesn't. Try this;

    Code:
    Private Sub Form_Load()
        Dim N As Double
        N = 6.78845934253293E-05
        'N = Format(N, "0.00000000")
        N = CDec(N)
        MsgBox N
    End Sub
    Hi Steve,

    Thanks for your reply. There is a difference between the example I gave and yours: You are converting a variable declared as a Double to a Decimal and then assigning the converted value back to that same variable causing it to be implicitly converted back to a Double. Either use "MsgBox CDec(N)") or use a numeric literal instead of a variable declared as a Double. As I did.
    Last edited by Peter Swinkels; Jan 13th, 2019 at 08:35 AM. Reason: typo

  9. #9
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    427

    Re: VB Satoshi convert help

    Hi Peter, how right you are. Many thanks.

  10. #10
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    640

    Re: VB Satoshi convert help

    Quote Originally Posted by Steve Grant View Post
    Hi Peter, how right you are. Many thanks.
    You're welcome. :-)

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width