如何将文本框格式化为货币c#.Net

时间:2016-04-10 22:59:46

标签: c# windows-phone-8.1 currency-formatting

如何将此文本框格式化为GBP货币,例如0.00?:`

private void textBox_LostFocus(object sender, RoutedEventArgs e)
{
    double amount = 0.0d;
    if (Double.TryParse(textBox.Text, NumberStyles.Currency, null, out amount))
    {
        textBox.Text = amount.ToString("C");
    }
}

那个代码是卢比,但我只是测试它。我无法找到任何有用的东西。 文本框xaml:

 <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="51" Margin="10,461,0,0" TextWrapping="Wrap" Text="{Binding TotalValue}" VerticalAlignment="Top" Width="120" KeyDown="textBox_KeyDown" TextChanged="textBox_TextChanged_1" LostFocus="textBox_LostFocus"/>

现在的价值就像是1.5怎样才能达到1.50?

TotalValue应设置为格式化货币。

private double totalValue;

public double TotalValue
{
    get { return totalValue; }
    set
    {
        totalValue = value;
        OnPropertyChanged("TotalValue");
    }
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Menu.PassedData data = e.Parameter as Menu.PassedData;

    if (data != null) //If data is not 0 
    {
        PassedData.Add(data); //Increment data in list view
        double tempTotalValue = 0;
        foreach (var record in PassedData)
        {
            tempTotalValue = tempTotalValue + record.Value;
        }
        TotalValue = tempTotalValue;
    }
}

0 个答案:

没有答案