我需要在网页中匹配无数个数字.
我需要能够匹配以下所有格式:
100 $
99$
$99
$ 8
$.99
$ .8
$ 99.8
.99$
.99 $
9.2 $
1.2$
Run Code Online (Sandbox Code Playgroud)
等效使用逗号:
444,333
22,333
1,222
11,111,111
333,333,333,333.01132
Run Code Online (Sandbox Code Playgroud)
或空格:
444 333
22 333
1 222
11 111 111
333 333 333 333.01132
Run Code Online (Sandbox Code Playgroud)
这对我来说真的很难.我习惯玩regexp,但我完全没有写出一些防弹证明.通常http://www.regexlib.com有解决方案,但不适用于此.
我想不出除了使用regexp之外的其他方法,因为它是纯文本搜索/替换.
请帮助我,我已经陷入这些问题几天了.我有一个Web表单,将在asp.net中付款,语言是C#.
文本框用于接受来自用户的货币金额.我的要求是,如果用户输入例如75,则在_TextChanged事件中它将切换到75.00.我得到了这部分工作.但我的代码没有检查位置后的三个字符.并删除多余的零.我的问题:1.如果输入超过小数点后的两位数,如何删除多余的零?2.如果用户未在文本框中输入任何数字,我该怎么办?我试过,我只是得到错误或它弄乱了整个代码.
protected void txtAmount_TextChanged(object sender, EventArgs e)
{
string textBoxData = txtAmount.Text;
int textLength = textBoxData.Length;
int position = txtAmountToPay.Text.IndexOf("."); //Position is the decimal
if (position == -1)
{
textBoxData = textBoxData + ".50"; // when you enter 75 you get 75.50
}
if (position == textLength -2 )
{
textBoxData = textBoxData + "4"; // when you enter 75.0 you get 75.04
}
if (position == textLength -1)
{
textBoxData = textBoxData + "30"; // when you enter …Run Code Online (Sandbox Code Playgroud) 我正在网站上整合Sagepay表格.我已经在测试模式下完成了事务,但是当我实现它时,我得到以下错误
表单事务错误状态缺少格式错误的3045货币字段
我有这样的例子:
10.99美元
LIR10.99
10.99美元
$ 10.99
因此输入数据可以是任何'symbolfloat'或'symbol float'.
我做了这样的事情:
float((str(param[2]).translate(None, '$USDLIR')))
Run Code Online (Sandbox Code Playgroud)
但它可以是任何世界货币,因此它必须是通用转换器.
目前我正在使用 AddThis 生成的社交分享按钮。但是我想在我的网站上使用相同的共享按钮而不添加其他网站的代码。
那么,如何开发同一个分享按钮呢?
我的应用程序中有欧元货币格式化程序.当用户最初将其从任何其他货币设置为欧元时,格式化程序将其显示为€1000.当应用程序重新启动时,它会将其更改为1000 €,有时它甚至会结束€1000 €!知道这里发生了什么吗?
func formatAsCurrency(currencyCode: String) -> String? {
let currencyFormatter = NSNumberFormatter()
let isWholeNumber: Bool = floor(self) == self
currencyFormatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
currencyFormatter.maximumFractionDigits = isWholeNumber ? 0 : 2
currencyFormatter.minimumFractionDigits = isWholeNumber ? 0 : 2
currencyFormatter.locale = NSLocale(localeIdentifier: currencyCode)
if let currencyString = currencyFormatter.stringFromNumber(self) {
return currencyString
}
return nil
}
Run Code Online (Sandbox Code Playgroud) 我是一个新的python,我想测试它,我的想法是制作一个脚本,这将看到你可以购买多少东西一定数量的钱.这个项目的问题是,我不知道删除小数,就像你喜欢如果你有1,99美元和苏打水花费2美元,你在技术上将没有足够的钱.这是我的脚本:
Banana = 1
Apple = 2
Cookie = 5
money = input("How much money have you got? ")
if int(money) >= 1:
print("For ", money," dollars you can get ",int(money)/int(Banana),"bananas")
if int(money) >= 2:
print("Or ", int(money)/int(Apple), "apples")
if int(money) >= 5:
print("Or ", int(money)/int(Cookie)," cookies")
else:
print("You don't have enough money for any other imported elements in the script")
Run Code Online (Sandbox Code Playgroud)
现在,如果我输入例如9,在这个脚本中,它会说我可以获得1.8个cookie,我怎么说它在输入fx 9时我可以获得1个cookie?
我从其他 SO 问题中知道的事情:
当我在内存中有 101 件物品的账单,每件物品价值 1.00004999999999999 时,我将所有价值为 1.000049999999999999 美元的 BigDecimals(或所有整数,如果我选择该表示法)相加,计算出的总数为 101.00509.9999 美元,即 1999999999 美元。
如果我在数据库中存储 4 个小数位,每个项目将被四舍五入并存储为 1.0000 美元,当我从数据库中提取它们并将它们相加时,我得到 101.0000 美元,四舍五入为 101.00 美元。
如果我将存储精度提高到十进制(19,5),我需要 1001 个项目而不是 101 个项目才能实现,但这仍然是可能的。它总是可能发生的事情,尽管一种可能的解决方案是将存储精度提高到如此之多,以至于发生这种错误的可能性比闪电击中计算机的可能性要小。
到目前为止,我的解决方案是从不使用 BigDecimal,而是始终使用 BigDecimal.setScale(4),它将其设置为 4 个小数位。你会建议一种不同的方法吗?
我知道行不通的事情:
其他注意事项:
我们的 WooCommerce 网站有 2 种货币。主要货币是印度卢比,次要货币是美元(使用货币切换器)。我尝试以美元下订单,但 YITH 发票显示发票中的主要印度卢比符号。
我尝试更改为各种可用的货币切换器插件,但发票中的符号不会更改,它只是采用默认货币符号。
我什至尝试将 'get_woocommerce_currency_symbol()' 添加到货币参数数组到 YITH 函数。我需要帮助。使用的插件是 YITH Invoice ver: 1.3.11。
function yith_get_formatted_price ( $price, $args = array () ) {
extract ( apply_filters ( 'wc_price_args', wp_parse_args ( $args, array (
'ex_tax_label' => false,
'currency' => get_woocommerce_currency_symbol (),
'decimal_separator' => wc_get_price_decimal_separator (),
'thousand_separator' => wc_get_price_thousand_separator (),
'decimals' => wc_get_price_decimals (),
'price_format' => get_woocommerce_price_format (),
) ) ) );
$negative = $price < 0;
$price = apply_filters ( 'raw_woocommerce_price', floatval ( …Run Code Online (Sandbox Code Playgroud) 我在 javascript 中显示货币值,我想用每个值显示 $,我也想用 ,(逗号)表示千位,但我不想四舍五入小数点后的数字,而且我也没有固定的限制许多数字将在小数点后。
它是为 en-AU
例如
45000 -> 45,000 美元
3.6987 -> 3.6987 美元
3 -> 3 美元
4.00 -> 4.00 美元
是否有任何内置的 JavaScript 方法或库可以帮助实现这一目标?