请看以下示例:
>>> from decimal import Decimal
>>> nrml_price = Decimal('0.59')
>>> discounted = nrml_price / 3 # Taking 2/3 off the price with a coupon
Decimal('0.1966666666666666666666666667') # Customers don't have fractions of a penny
>>> (nrml_price / 3).quantize(D('0.00')) # So I quantize to get 2 decimal places
Decimal('0.20') # Ca fait combien? Cest vingt cents.
Run Code Online (Sandbox Code Playgroud)
问题是,我现在已经在技术上向客户收取超过预期价格的费用,尽管不到3/10美分,但技术上不正确.
我如何克服这样的问题?我是否将其视为生活中的事实,或者是否有可接受的方式来做这种事情(例如,总是向客户收取最近的便士)?
我在使用正则表达式时遇到了一些问题我正试图花钱$ 28.84并将其作为便士存入我的数据库.现在我正在使用它
$amount="$28.84";
$amount_number= ereg_replace("[(^0-9)(.)(0-9){2}]", "", $amount ); //return a decimal
$store_amount = $amount_number*100; //get number of pennies
Run Code Online (Sandbox Code Playgroud)
我也试图删除","""和任何不是十进制数字的数字.
我TextBox在一个WPF窗口中绑定了一个类型窗口的依赖属性double(见下文).每当用户键入TextBox时
TextBox是空的,或键入的文本被错误地接受.例如:如果我在这些场景中输入'5',结果文本为"$ 5.00",但插入符号位于'$'之后的'5'之前.如果我尝试键入"52.1",我会收到"$ 2.15.00".
<Window x:Class="WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="154" Width="240" Name="ThisWindow"
Background="{StaticResource {x:Static SystemColors.AppWorkspaceBrushKey}}">
<Grid>
<TextBox Text="{Binding ElementName=ThisWindow,
Path=Amount,
StringFormat={}{0:c},
UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
MinWidth="100" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
如果我删除UpdateSourceTrigger属性,它会正确键入,但不保持货币格式.
有任何想法吗?
当我们转换String.Format("{0:C}", 126.45)它返回$ 126.45
但如果我们转换 String.Format("{0:C}", -126.45)它返回($ 126.45)
为什么负转换返回括号?如果我们不想要这个括号怎么办?
我需要知道如何服用
10.25并将其转为1025
基本上它需要从任何数字中移除句号,例如1500.25它应该是150025
有没有快速的方法来验证NSString是否格式化为美国货币?
所以我要确认的是字符0是$,以下字符是数字,除了string.length-3,它可以是小数(显示更改是可选的).
所以这通过1000美元,这通过1000美元,但这将失败1000美元.
谢谢
我正在使用dompdf来创建一个pdf.当我传递₹给pdf它转换成?
如何使用dompdf在pdf中显示印度货币符号?
我在过去几年里使用过这段代码,但google似乎已经改变了一些链接.出于某种原因,我收到此错误消息:
"输入字符串的格式不正确."
在以下行中:
decimal rate = System.Convert.ToDecimal(match.Groups[1].Value);
Run Code Online (Sandbox Code Playgroud)
我的代码:
try
{
WebClient web = new WebClient();
string url = string.Format("https://www.google.com/finance/converter?a={2}&from={0}&to={1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
string response = web.DownloadString(url);
Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
Match match = regex.Match(response);
decimal rate = System.Convert.ToDecimal(match.Groups[1].Value);
return rate;
}
catch
{
return 0;
}
Run Code Online (Sandbox Code Playgroud) 什么是获得十进制值的最佳方法$232,680.00是否可以没有正则表达式.
这也行不通 -
decimal.TryParse(Response.assess_market_value, NumberStyles.Currency, CultureInfo.InvariantCulture, out marketTotalValue);
Run Code Online (Sandbox Code Playgroud)