变量中的零填充

问题描述 投票:0回答:0

以下是我的场景: 输入值=1234 输入范围= 2

预期产量=1200

输入值=12345 输入范围= 3

预期产量=12000

问题是用等于输入范围的零替换右边的字符/数字数

我遵循以下逻辑:

{
    "name": "RoundPad",
    "properties": {
        "activities": [
            {
                "name": "ForEach1",
                "type": "ForEach",
                "dependsOn": [],
                "userProperties": [],
                "typeProperties": {
                    "items": {
                        "value": "@range(1,pipeline().parameters.Range)",
                        "type": "Expression"
                    },
                    "isSequential": true,
                    "activities": [
                        {
                            "name": "Set variable1",
                            "type": "SetVariable",
                            "dependsOn": [],
                            "userProperties": [],
                            "typeProperties": {
                                "variableName": "TempPower",
                                "value": {
                                    "value": "@string(mul(int(variables('Power')),10))",
                                    "type": "Expression"
                                }
                            }
                        },
                        {
                            "name": "Set variable2",
                            "type": "SetVariable",
                            "dependsOn": [
                                {
                                    "activity": "Set variable1",
                                    "dependencyConditions": [
                                        "Succeeded"
                                    ]
                                }
                            ],
                            "userProperties": [],
                            "typeProperties": {
                                "variableName": "Power",
                                "value": {
                                    "value": "@variables('TempPower')",
                                    "type": "Expression"
                                }
                            }
                        }
                    ]
                }
            },
            {
                "name": "Set variable3",
                "type": "SetVariable",
                "dependsOn": [
                    {
                        "activity": "ForEach1",
                        "dependencyConditions": [
                            "Succeeded"
                        ]
                    }
                ],
                "userProperties": [],
                "typeProperties": {
                    "variableName": "Output",
                    "value": {
                        "value": "@string(mul(div(int(pipeline().parameters.Input),int(variables('Power') )),int(variables('Power'))))",
                        "type": "Expression"
                    }
                }
            }
        ],
        "parameters": {
            "Input": {
                "type": "string",
                "defaultValue": "1234"
            },
            "Range": {
                "type": "int",
                "defaultValue": 2
            }
        },
        "variables": {
            "TempPower": {
                "type": "String",
                "defaultValue": "1"
            },
            "Output": {
                "type": "String"
            },
            "Power": {
                "type": "String",
                "defaultValue": "1"
            }
        },
        "annotations": []
    }
}

有没有比利用 For each iteration 和 multiple variables 更好的方法来做到这一点? 我可能在这里遗漏了一些东西

azure-data-factory azure-data-factory-2
© www.soinside.com 2019 - 2024. All rights reserved.