I'm having a problem decimally formatting my code in Objective-c, I'd like to take advantage of only 2 decimal places of my variable that is float
.
Ex: Variable value discount = 4.00043621
I need to be stored only 4.00
I was able to format only with StringWithFormat
, as the example below:
NSString* decimalFormatado = [NSString stringWithFormat: @"%.02f", discount];
In this way the value of the variable decimalFormatado
was the way I wanted "4.00" but in String
. and I need it to continue in float
, since I will need to use it as float
in a conditional structure later.
Any suggestions for how best to do this?
I'm looking for a way to take advantage of only the 2 boxes after the comma with a direct formatting, convert from string
to decimal
with both houses I think is not good practice.