Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to remove decimals from string
Message
From
20/04/2010 14:18:19
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01461123
Message ID:
01461176
Views:
39
>>>>>>Using C#, how can I remove the decimals from a string? For example:
>>>>>>
>>>>>>"123.00" convert to "123"
>>>>>>
>>>>>>Thanks,
>>>>>
"123.00".Substring(0,s.IndexOf("."))
?
>>>>
>>>>
>>>>hmmmm
>>>
>>>Wha? Didn't work for you ? :-}
>>
>>
>>
>>If you define s before
>>
>>Also, when the string does not contain any dot you'll get a nice exception
>
>OK. 'Twas drive-past coding. So's this:
string s = "123.00";
>string cut = s.IndexOf(".") > 0 ? s.Substring(0, s.IndexOf(".")) : s;
>
>> I'll do unit testing later :-}
haha
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform