// 単位変換対象外項目
private Set<String> notColList {get;set;}
notColList = new Set<String>{'転換対象外の数値項目__c'};
obj = (Obj__c)COM_Util.convertUnit(Obj__c.sObjectType,obj,notColList,false);
/**
* 円と万円を単位変換
* @param type :sObjectType
* @param obj :対象オブジェクト
* @param notColList :転換対象外項目セット
* @param flg : ture: 円→万円; false:万円→円
* @return パラメータ内容
*/
public static sObject convertUnit(Schema.sObjectType type,sObject obj,Set<String> notColList,Boolean flg){
Schema.DescribeSObjectResult objDescribe = type.getDescribe();
Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
for(string fieldName :fieldMap.keyset()){
DescribeFieldResult dfr = fieldMap.get(fieldName).getDescribe();
if('DOUBLE'.equalsIgnoreCase(String.ValueOf(dfr.getType()))){
if(obj.get(fieldName)!=null && !notColList.contains(fieldName)){
decimal tempValue = 0;
if(flg){
tempValue = (decimal)obj.get(fieldName)/10000;
}else{
tempValue = (decimal)obj.get(fieldName)*10000;
}
obj.put(fieldMap.get(fieldName),tempValue);
}
}
}
return obj;
}
単位変換 共通
最新推荐文章于 2025-07-02 16:31:45 发布