# 函数常见问题归纳总结

来源快照：`result_data_new_260518.json`

- 来源 ID：`1244839560128282694`
- 模块：低代码平台e-builder
- 目录：常见问答 - 动作流
- space ID：`1157961794811633670`
- 原文链接：未提供
- 产品基线：未提供

## 正文

#### **问题1：****运算操作符函数+** -×÷计算结果只会保留两位小数，需要保留更多位数或者不保留位数需要怎么处理

**处理方案：** 使用函数**MATHOPERATING** 去实现

#### **问题2：日期和时间拼接成日期时间，拼接的中间的空格怎么加**

**处理方案** ：使用CONTACT函数，中间的空格直接鼠标点中，键盘Tab键点击下即可

![](https://weapp.eteams.cn/papi/file/preview?fileId=1247439170726232070&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题3：****如何对数据去重，如 1,2,3,1 去重后的结果为  1,2,3****（注：260401基线已加标准函数：DEDUPLICATEARRAYTOSTRING）**

**处理方案：** 写自定义JS函数去实现：

function uniqueNumberString2(params) {  
  var numberMap = {};  
  var resultArr = [];  
  var arguments = params.split(',');

  for (var i = 0; i < arguments.length; i++) {  
    var currentArg = (arguments[i] || '').toString().trim();  
    if (currentArg === '') {  
      continue;   
    }

    var numberItems = currentArg.split(',');  
    for (var j = 0; j < numberItems.length; j++) {  
      var num = numberItems[j].trim();  
      if (num === '') {  
        continue;  
      }

      if (!numberMap[num]) {  
        numberMap[num] = true;  
        resultArr.push(num);  
      }  
    }  
  }

  return resultArr.join(',');  
}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1247437280945643521&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题4：多个参数值替换，IF满足不了时**

**处理方案：** 使用自定义函数

function selectValueConvert(a){

if('选项1'.equals(a)){

return '123';

}if('选项2'.equals(a)){

return '789';

}else{

return '456';

}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1251238988452208641&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题5：获取指定日期的13位时间戳**

**处理方案：** 使用自定义函数

function shijianchuo(params){

var date = new Date(params);

var timestamp = date.getTime();

return timestamp.toString();

}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1251238829371637763&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题6：数字比较**

**处理方案：** 使用自定义函数

function comparingNum(a){

if (a > 100 && a < 200) {

    return 1;

} else if(a > 200 && a < 300) {

    return 2;

}else if(a > 300 && a < 400){

return 3;

}

}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1251238915447144450&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题7：如何获取32位uuid**

**处理方案：** 使用自定义函数

function generate32BitUUID() {

return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {

var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);

return v.toString(16);

});

}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1247440733957210113&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题8：如何获取指定日期那个月份的第一天和最后一天**

**处理方案：** 使用自定义函数

**最后一天：**

function getLastDayOfMonth(date) {

var d = date?new Date(date) : new Date();

var date1= new Date(d.getFullYear(), d.getMonth() + 1, 0);

var year = date1.getFullYear();

var month = date1.getMonth() + 1;

var day = date1.getDate();

month = month < 10 ? '0' + month : month;

day = day < 10 ? '0' + day : day;

return year + '-' + month + '-' + day;

}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1259026404025786371&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

**第一天：**

function getFirstDayOfMonth(date) {

var d = date?new Date(date) : new Date();

var date1= new Date(d.getFullYear(), d.getMonth(), 1);

var year = date1.getFullYear();

var month = date1.getMonth() + 1;

var day = date1.getDate();

month = month < 10 ? '0' + month : month;

day = day < 10 ? '0' + day : day;

return year + '-' + month + '-' + day;

}

![](https://weapp.eteams.cn/papi/file/preview?fileId=1259026507004338181&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题8：如1,2,3逗号隔开的数据，如何可以用去循环使用**

**处理方案：** 使用SPLIT函数转成数组格式[1,2,3]然后去使用

![](https://weapp.eteams.cn/papi/file/preview?fileId=1268890350565015556&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

![](https://weapp.eteams.cn/papi/file/preview?fileId=1268890938874871812&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

注：第二个参数一般都是输入英文逗号，用英文逗号隔开

![](https://weapp.eteams.cn/papi/file/preview?fileId=1268890517931982868&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

#### **问题9：需要在IF函数中判断两个内容是否相等，相等函数总是判断不对**

![](https://weapp.eteams.cn/papi/file/preview?fileId=1268897424298115079&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)

**处理方案：** =函数一般是判断数字类型的，字符比较用函数OBJECTEQUALS

![](https://weapp.eteams.cn/papi/file/preview?fileId=1268897939629621256&type=redirect&customParam=%7B%22isExtDist%22%3Atrue%2C%22distributeId%22%3A%22%22%2C%22externalId%22%3A%22%22%2C%22appId%22%3A%22%22%7D)
