Reputation: 838
I'm trying to figure out a way (or find a library) that supports long money string conversion into a decimal. I'm not sure if there's a practical way to do this with all the possible combinations.
Basically, I would need to convert something like two hundred and thirteen dollars and fifty-two cents
into 213.52
Does anybody know of a library that handles this already or a solution that has already been posted? I've Googled for about an hour and came up with turning dollar amounts in words.
Upvotes: 4
Views: 263
Reputation: 3116
You may try WordToNumberConverter NuGet
https://www.nuget.org/packages/WordToNumberConverter/
But you should be sure input matching the format.
Example of right input : "twenty nine thousand and fifty five"
while
Example of wrong input : "twenty nine thousands and fifty five"
How to use:
WordToNumberConverter.WordToNumberConverter inst =
new WordToNumberConverter.WordToNumberConverter();
var ddd = inst.ConvertWordToNumber("twenty nine thousand and fifty five");
Upvotes: 3
Reputation: 399
Humanizer should be able to help you with this and more. You can try the following link "https://github.com/Humanizr/Humanizer#number-to-words". It is quite simple to use as you can see in the example
1.ToWords() => "one"
10.ToWords() => "ten"
11.ToWords() => "eleven"
122.ToWords() => "one hundred and twenty-two"
3501.ToWords() => "three thousand five hundred and one"
Upvotes: -1