cancel
Showing results for 
Search instead for 
Did you mean: 

How to write calculation for currency and decimal in ByDesign by using cloud application studio.

0 Kudos

How to write calculation for following calculation and assign to final value to currency type element?

  • element Price: Amount;
  • element NPrice: Amunt
  • element Quantity: Decimal;
  • Price<----$100
  • Quantity<----2
  • Var new_Price= Price X Quantity
  • NPrice= new_Price

And how to round the finale answer in to 2 decimal places?

Accepted Solutions (1)

Accepted Solutions (1)

JohnMeadows
Product and Topic Expert
Product and Topic Expert

Pesala,

In ByDesign all currencies are assigned the number of decimal places based on the ISO standard for the currency.

You are using an amount element - which is a compound data type made up of two components Decimal Value (content) and Currency Code. And you also have a quantity field - which if you are using the data type "Quantity" this is also a compound field made up of Decimal Value (content) and UnitCode (for UoM)

My BO looks like this

[Label("Original Price")]	element Price: Amount;
[Label("New Price")]		element NPrice: Amount;
[Label("Quantity")]		element OrigQty: Quantity;

the result of the calculation is rounded automatically based on the number of decimal places assigned to the currency code.

var origPrice  = this.Price.content;
var currency = this.Price.currencyCode;
var newPrice;
var pieces = this.OrigQty.content;

newPrice = origPrice * pieces;

this.NPrice.currencyCode = currency;
this.NPrice.content = newPrice;

So my result looks like this:

I hope this helps

John

0 Kudos

Hi John,

Thank you very much for your answer with your clear explanation.

Answers (0)