Problem numbers after the comma

1

Hello, I have this code on a button.

txtresultado.Text = Math.Round(txtsalmin.Text * 0.2, 2).ToString

In that it takes the value of the salmin.text and multiply poe 0.2 and appears in txtresultado.text with a maximum of 2 houses after the comma. And my problem is the following, for example if doing 937 * 0.2 equals 187.4 and it appears in txtresultado.text, so far everything is fine, but I would like it to appear 187,40 because I am working with money in this system and have to appear the 2 houses after the comma.

Could someone help me?

    
asked by anonymous 29.11.2017 / 17:49

1 answer

0

You can specify the number of decimal places in the ToString () method as follows:

txtresultado.Text = Math.Round(txtsalmin.Text * 0.2, 2).ToString.("N2")
txtresultado.Text = Math.Round(txtsalmin.Text * 0.2, 2).ToString.("F2")

Here's a small example here

Imports System

Public Module modmain
   Sub Main()
       Console.WriteLine ( Math.Round(10937 * 0.2, 2).ToString())     
       Console.WriteLine ( Math.Round(10937 * 0.2, 2).ToString("N2"))   
       Console.WriteLine ( Math.Round(10937 * 0.2, 2).ToString("F2")) 
   End Sub
End Module

Result:

2187.4
2,187.40
2187.40
    
29.11.2017 / 17:54