Share via


Set Precision for multiplication result in Logic App

Question

Friday, March 29, 2019 9:30 AM

Multiplication Function in Azure Logic App is returning 14.12999999 (4.71 X 3), we need 14.13 what is inbuilt function to round. Or what is way to limit to 2 precision.

All replies (4)

Monday, April 1, 2019 10:01 AM âś…Answered

For now, there is still no generalized rounding solution in Logic Apps. However you need build solutions specific to your data.

1. Here is an approach you could round decimals to two for display purpose

2. Create an Azure Function (below sample code) to round off the values and Call that function with in your Logic App Workflow.

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string number = req.Query["number"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    number = number ?? data?.number;
double roundOffValue = Convert.ToDouble(number);
   roundOffValue =  Math.Round(roundOffValue,2);
 log.LogInformation(Math.Round(roundOffValue,2).ToString());
    return number != null
        ? (ActionResult)new OkObjectResult($"RoundOffValue, {roundOffValue}")
        : new BadRequestObjectResult("Please pass a number on the query string or in the request body");
}


Tuesday, April 2, 2019 5:36 AM

Hello Vishal,

Any update on this ?


Tuesday, April 2, 2019 8:42 AM

Thanks for reply.

Yes we had given a thought of same but don't feel good just to maintain\write another component for basic task.

-Vishal.


Wednesday, December 18, 2019 10:33 AM

There is no round function in LogicApps. But we can do this without using any function apps or javascript. 

With help of following mathematical logic we can round value to 2 decimal:

div(add(mul(variables('Value addition'),1000),sub(if(greaterOrEquals(mod(mul(variables('Value addition'),1000),10),5),10,0),mod(mul(variables('Value addition'),1000),10))),1000) 

Thanks

~Siddharth Poddar