iphone - How to get decimal value from text field -


in iphone app need user able enter decimal amount in textfield , need convert float.

i use following code:

cgfloat amount = [amounttextfield.text floatvalue]; 

it works fine when user , use point decimal values, european users use comma instead doesn't value. should replace , . before using floatvalue or there better way?

a better way use nsdecimalnumber, floats ugly anyway. because 2.2 should 2.2 , not 2.2000000477

nsdecimalnumber *amount = [nsdecimalnumber decimalnumberwithstring:amounttextfield.text locale:[nslocale currentlocale]]; 

if don't want use nsdecimalnumber have nsnumberformatter , nsnumber. convert cgfloat (which name float) too.

when comes localization want use built-in functionality. when use string editing doing wrong.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -