生成不同(随机)货币金额到不同的地点值 [英] Generate different (random) currency amounts to different place values

查看:79
本文介绍了生成不同(随机)货币金额到不同的地点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小项目,我试图产生不同的货币金额,从1.00美元到9.99美元不等。我想通过以下选项之一生成这些金额:Dollars&美分(仅限美元),美分(仅限)

美元和美元Cents功能和Cents功能工作正常,但我似乎无法让Dollar功能正常工作(即:$ 5.00,$ 2.00,$ 8.00)。我做错了什么?



我的尝试:



I have a small project that I am trying to generate different currency amounts ranging from under $1.00 to $9.99. I would like to generate these amounts by one of the following options: Dollars & Cents, Dollars (only), Cents (only)
The Dollars & Cents function and the Cents function work OK, but I cannot seem to get just Dollar function to work(ie: $5.00, $2.00, $8.00). What am I doing wrong?

What I have tried:

Public Class Form1
    Public MaxAmount As Integer
    Public FrmattedAmt As New Random

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        RadioButton4.Hide()
        RadioButton5.Hide()
        RadioButton6.Hide()
        Button2.Enabled = False

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        If RadioButton1.Checked = False And RadioButton2.Checked = False And RadioButton3.Checked = False Then Exit Sub

        Select Case True

            Case RadioButton1.Checked
                MaxAmount = 999

            Case RadioButton2.Checked
                MaxAmount = 9

            Case RadioButton3.Checked
                MaxAmount = 99

        End Select

        Randomize()

        TextBox1.Text = FormatCurrency(Math.Round(FrmattedAmt.Next(0, MaxAmount) / 100, 2), 2)

        RadioButton1.Enabled = False
        RadioButton2.Enabled = False
        RadioButton3.Enabled = False

        Button1.Enabled = False
        Button2.Enabled = True

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Button1.Enabled = True
        RadioButton1.Checked = False
        RadioButton1.Enabled = True
        RadioButton2.Checked = False
        RadioButton2.Enabled = True
        RadioButton3.Checked = False
        RadioButton3.Enabled = True
        RadioButton4.Hide()
        RadioButton5.Hide()
        RadioButton6.Hide()
        TextBox1.Clear()
        Button2.Enabled = False

    End Sub
End Class

推荐答案

1.00到


9.99。我想通过以下选项之一生成这些金额:Dollars&美分(仅限美元),美分(仅限)

美元和美元Cents函数和Cents函数工作正常,但我似乎无法让Dollar函数起作用(即:
9.99. I would like to generate these amounts by one of the following options: Dollars & Cents, Dollars (only), Cents (only)
The Dollars & Cents function and the Cents function work OK, but I cannot seem to get just Dollar function to work(ie:


5.00,


这篇关于生成不同(随机)货币金额到不同的地点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆