The power of community is awesome and from that open source is taking place. With openness in mind the world of software development is getting better, more and more cool open source libraries popping up and this is not exceptional for .NET platform.
Humanizer is one of cool open source library for .NET platform. It has many extension methods that can save your life as software developer when deal with string and number manipulation and other types as well as stated by its author :
Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities
In this blog post i’m just gonna show you how to use Humanizer to convert a number into words ( C# number to words), for other functionalities just refer to its official website.
C# Number To Words
Open up your Visual Studio, create new Console Project and install Humanizer using Nuget package manager either via graphical form or Package Manager Console, i prefer the latest. If you can’t find where Package Manager Console is simply open it in View->Other Windows->Package Manager Console
Type this command “Install-Package Humanizer” and hit enter
Now is the time for the magic. Add some lines of code below and see what happen next
1 2 3 4 5 6 7 8 9 10 11 12 |
static void Main(string[] args) { string word=3511.ToWords(); Console.WriteLine(word); Console.WriteLine(); string ordinalword = 21.ToOrdinalWords(); Console.WriteLine(ordinalword); Console.WriteLine(); Console.ReadLine(); } |
See?
Very straightforward c# number to words!
Thank you to Scott Hanselman for pointing this out and big thanks to the author