web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Performing Mathematical Calculations in Business Central Visual Studio Code

(0) ShareShare
ReportReport
Posted on by 203

Hey Everyone.

I have created a hypothetical task in which I am trying to perform a mathematical calculation in Business Central and record the output values in a subledger account. An example of the calculation is 

Interest on Savings =  $50 * 0.047 (interest rate) * 31/365 (number of days in a month divide by number of days in a year) = $0.20

I have done a similar calculation when i wrote a C++ code in which I would write a procedure and call that procedure to perform the calculation but how can i accomplish something similar in Visual Studio Code in Business Central. I know that I can use CodeUnit which is similar to a procedure I believe in C++ but my worry is how do I record the output into a GL account? Any thoughts would be nice or any experience with writing a similar code with mathematical calculation would also be appreciated. 

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    you can write the formula like in c++.

    to add the result to a g/l account you have to create a g/l entry.

  • Suggested answer
    THE Italian Profile Picture
    Microsoft Employee on at

    You have to create a function inside a codeunt where you pass the parameters you need. 

    Every time you need that calculation, you have to reference that codunit into your object and call the function where you need most. 

  • attique Profile Picture
    10 on at

    I am wondering if you can add an extension (field) to the payment journal and let the user enter some values and let the system output the correct interest value. Do you think that is a good option for you and practicable?

  • Aneeq Profile Picture
    203 on at

    what if i have different scenarios that determines how the calculation will be done? I am thinking if I should ask the user to input certain fields in the payment journal and use IF THEN statements to figure out which calculation to perform. Will I have to create an extension by adding fields to payment journal and referencing the codeunit to those field? Can that happen?

  • Suggested answer
    THE Italian Profile Picture
    Microsoft Employee on at

    Yes. This can be done. You could create create field A and field B where you gather values and then field C is enabled=false and just trigger the result of the formula after validation of the fields

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 580 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 480 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 261 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans