如何创建一个可以使用 VB.NET 将实数格式化为货币字符串的函数?

How to create a function that can format real numbers to currency string using VB.NET?

我需要创建一个函数,可以将实数格式化为以下格式的货币:

  1. 它应该包括一个前导货币字符,例如 $
  2. 千位逗号分隔符
  3. 四舍五入到定义的小数位数
  4. 用前导零和尾随零填充

固定

Imports System
Imports System.Collections

Public Module Module1

    Public Sub Main()
        Console.WriteLine(Convert(12345678))
    End Sub

    Function Convert(number) As String

        Dim str as String = ""

        While number > 0

            str = (number MOD 1000).ToString() + str
            number = number \ 1000

            If number > 0

                str = "," + str

            End If

        End While

        Return "$" + str

    End Function

End Module

https://dotnetfiddle.net/EYJvMC

Imports System.IO

Public Module Module1

    Dim value, result As Decimal

    Public Sub main()
        result = convert()
        Console.ReadKey()
    End Sub

    Function convert()

        Console.Write("Enter value: ")
        value = Console.ReadLine()
        Console.Clear()
        Console.WriteLine("$" & value.ToString("#,###,###.00"))
        Return value

    End Function

End Module