0

Hello I need help getting this to display the 3 outputs (Euro, Franc, Rand) with 2 decimal places (1.00)
I have all the calculations done so this is what I have as my code:

Public Class frmConvert

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub


    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

        Me.Close()

    End Sub

    Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click

        txtEur.Text = txtDollar.Text * 0.89
        txtFranc.Text = txtDollar.Text * 0.95
        txtRand.Text = txtDollar.Text * 11.54


    End Sub
End Class
4
Contributors
3
Replies
21
Views
2 Years
Discussion Span
Last Post by Minimalist
Featured Replies
  • 1
    ddanbe 2,525   2 Years Ago

    Hi, Cameron 2, welcome. :) Use Format: ' Returns "5,459.40". TestStr = Format(5459.4, "##,##0.00") Taken from the example at the end of [this webpage](https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.format%28v=vs.110%29.aspx) Read More

  • Alternative: [String.Format](https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx) and [the "F" format specifier](https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#FFormatString). Read More

1

Hi, Cameron 2, welcome. :)
Use Format:
' Returns "5,459.40".
TestStr = Format(5459.4, "##,##0.00")
Taken from the example at the end of this webpage

Votes + Comments
Useful Resource
1

You are aware that you let the compiler do your conversions from text to decimal. Put option strict on and you will get some errors.Why? because you are multiplying text as in:

 txtEur.Text = txtDollar.Text * 0.89

It is much better to declare variables correctly like:
Dim DecDollar as Decimal =0 etc.

Votes + Comments
So true!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.