You need to sign in to do that
Don't have an account?
Ron Wild
Converting number fields to Integer
I see the the Apex Math.round() function is being deprecated in favor of Math.roundToLong().
It looks like we now have to use the following code to convert a number field value from double to integer for use in functions that require integer parms (e.g. Date.newInstance(year,month,day))
Integer intValue = Integer.valueOf(String.valueOf(Math.roundToLong(object.Some_Number_Field__c)));
Are there plans to allow casting or conversion from Long to Integer in Apex? Or at least, is there an easier way to achieve the same result than the example above?
Thanks,
It looks like we now have to use the following code to convert a number field value from double to integer for use in functions that require integer parms (e.g. Date.newInstance(year,month,day))
Integer intValue = Integer.valueOf(String.valueOf(Math.roundToLong(object.Some_Number_Field__c)));
Are there plans to allow casting or conversion from Long to Integer in Apex? Or at least, is there an easier way to achieve the same result than the example above?
Thanks,
objProperty.Square_Footage__c = '77.99';
objProperty.Square_Footage__c = Integer.valueOf( Math.Round( Decimal.valueOf(objUnit.Square_Feet__c.replaceAll(',', '') ) ) );
System.debug( Integer.valueOf( Math.Round( Decimal.valueOf(objUnit.Square_Feet__c.replaceAll(',', '') ) ) ));
This will give us round figure of 78;
2) Property.Square_Footage__c accepts only whole number.
Property.Square_Footage__c = Integer.valueOf( Math.Round( Decimal.valueOf(Unit.Square_Feet__c.replaceAll(',', '') ) ) );
System.debug( Integer.valueOf( Math.Round( Decimal.valueOf(objUnit.Square_Feet__c.replaceAll(',', '') ) ) ));
Cf: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_decimal.htm
Long Ln = Math.roundToLong(d);
Integer intVersion = Integer.valueOf(Ln);