计算特定字符后的字符数 [英] Count Characters After A Specific Character

查看:74
本文介绍了计算特定字符后的字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力让我的销售点计划看起来更专业。我将产品的价格作为整数存储在数据库中。然后,当我将这些产品价格导入我的程序时,价格看起来不太好。



例如,产品A的价格是2.00美元。这是我在数据库中存储在货币列中的内容。然后,我将其导入我的程序,并更改标签以显示价格:



I am trying to make my Point of Sales program look more professional. I am storing the prices of products in a database as integers. Then, when I import these product prices into my program, the prices do not look very good.

For example, the price of product A is $2.00. This is what I store in my database in a currency column. Then, I import this into my program, and change a label to display the price:

Label1.Text = "$" & ProductPrice





其中ProductPrice是整数。

但是,价格显示为$ 2.00,而不是显示为$ 2.00。我提出了这个解决方案来解决我的问题:





Where ProductPrice is an integer.
However, instead of the price being displayed as "$2.00", it is displayed as "$2". I came up with this solution that works to sort of solve my problem:

If InStr(ProductPrice.ToString, ".") > 0 Then
     Label1.Text = "$" & ProductPrice & "0"
Else
     Label1.Text = "$" & ProductPrice & ".00"
End If





您现在可能在想我没有一个问题,但上面的代码有问题。如果ProductPrice为2.5,它可以正常工作,因为它将其更改为$ 2.50,或者如果ProductPrice为2,则更改为$ 2.00,但如果价格为2.99,则它将把它改成$ 2.990。



现在最后,我的问题。如何计算小数位后的位数,这样如果小数位后面有2个数字,如2.99,则不会加零($ 2.99),但如果只有一个2.5 ,那么它会增加一个零($ 2.50)。



希望这是有道理的!



You might be thinking now that I don't have a problem, but there is a problem with the code above. It works fine if the ProductPrice is "2.5", as it changes it to "$2.50", or if the ProductPrice is "2", as that is changed to "$2.00", but if the price is "2.99", then it will change it to "$2.990".

Now finally, to my question. How can I count the number of digits after the decimal place, so that if there are 2 numbers after the decimal place, like "2.99", then it won't add the zero ($2.99), but if there is only one "2.5", then it will add a zero ($2.50).

Hopefully this makes sense!

推荐答案

2.00。这是我在数据库中存储在货币列中的内容。然后,我将其导入我的程序,并更改标签以显示价格:



2.00. This is what I store in my database in a currency column. Then, I import this into my program, and change a label to display the price:

Label1.Text = "


& ProductPrice
" & ProductPrice





其中ProductPrice是整数。

但是,不是显示为



Where ProductPrice is an integer.
However, instead of the price being displayed as "


2.00的价格,而是显示为
2.00", it is displayed as "


这篇关于计算特定字符后的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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