Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Last active December 11, 2015 21:19
Show Gist options
  • Save shiftkey/4661947 to your computer and use it in GitHub Desktop.
Save shiftkey/4661947 to your computer and use it in GitHub Desktop.
Formatting strings - looks to be same between XAML and regular .NET code
using System.Windows;
using System.Windows.Data;
using Xunit;
namespace ConsoleApplication2
{
public class Test
{
DependencyObject dObj = new DependencyObject();
[Fact]
public void Using_Binding_Should_Round_Down()
{
// arrange
double second = 127.533;
var binding2 = new Binding { Source = second, StringFormat = "{0:0}" };
var secondProperty = DependencyProperty.Register("Second", typeof(string), typeof(Program));
BindingOperations.SetBinding(dObj, secondProperty, binding2);
// act
var oneTwoSeven = (string)dObj.GetValue(secondProperty);
Assert.Equal("127", oneTwoSeven);
}
[Fact]
public void Using_Defaults_Should_Round_Down()
{
// arrange
double second = 127.533;
// act
var oneTwoSeven = second.ToString("0");
Assert.Equal("127", oneTwoSeven);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment