If I have a simple decimal in C#, and I want to ToString it without any dots, commas or decimals in any culture - how do i do it?
I tried the ToString("N0") with invariantculture which removes decimals, but it adds "." in my language.
What is the best way to do this?
You haven't clarified in the comments yet, but I suspect you want something like this?
3.14 -> 35.34543543 -> 5If that is correct then you simply need to cast your
decimalto anintwhich would strip the precision off and give you just the whole number.If you find yourself repeating this logic often you can make a simple extension method to keep it DRY:
And simply call it like so:
Simple fiddle here
EDIT
@HansPassant actually gave the simplest solution in the comments and I feel silly for not remembering:
This is a much better answer and if Hans posts an answer I suggest marking theirs as the solution.