## Forum Discussion

gdave
Regular Contributor
7 years ago

# Code Expression - Rounding Off

Hi all

Using below code express I was able to validate that value in field 2 is 25% of value in field 1.

aqConvert.VarToStr(Aliases.TransactConsole.omTransactFormWizardView.PanelDataEntry.PanelForm.FormTaxFreeWithdrawal.PanelMain.ScrollBoxAroundForm.PanelTFCFacInfo.GroupBoxTFCFac.EditFundValueFac.wText*0.25)

The above code works fine however the issue is when it comes to rounding off the value. Can someone please guide me on how do I round off the results

Example:

The value is 3798.415 and I would want to round it off to 3798.42

Thanks

Gary

• If it's DelphiScript that you're coding on, you can use the Round function but after a bit of mathematical manipulation.

So... got to brush off my math undergraduate degree a bit.

`Round(Aliases.TransactConsole.omTransactFormWizardView.PanelDataEntry.PanelForm.FormTaxFreeWithdrawal.PanelMain.ScrollBoxAroundForm.PanelTFCFacInfo.GroupBoxTFCFac.EditFundValueFac.wText * 25)/100`

Basically, taking the value of field one, multipliying by 100 to move the decimal point then multiplying by 0.25 (net multiply by 25).  Then, using the Delphi Round method available in TestComplete to round to the nearest integer...then dividing by 100 again to get the decimal point.

Give this a try.

### 4 Replies

• shankar_r
Community Hero

If you are using JavaScript then you can do like below,

`Log.Message(parseFloat("123.456").toFixed(2));Output:123.46 `
• gdave
Regular Contributor

shankar_r wrote:

If you are using JavaScript then you can do like below,

`Log.Message(parseFloat("123.456").toFixed(2));Output:123.46 `

Its basically a Delphi code.

Also I am trying to perform a property checkpoint test but its failing because the actual value displayed is 3798.42 and Expected value is calculated as 3798.415. Is there a way that it first round off the expected value and then validate it ? Please find the screenshot below. Thanks

• tristaanogre
Esteemed Contributor

If it's DelphiScript that you're coding on, you can use the Round function but after a bit of mathematical manipulation.

So... got to brush off my math undergraduate degree a bit.

`Round(Aliases.TransactConsole.omTransactFormWizardView.PanelDataEntry.PanelForm.FormTaxFreeWithdrawal.PanelMain.ScrollBoxAroundForm.PanelTFCFacInfo.GroupBoxTFCFac.EditFundValueFac.wText * 25)/100`

Basically, taking the value of field one, multipliying by 100 to move the decimal point then multiplying by 0.25 (net multiply by 25).  Then, using the Delphi Round method available in TestComplete to round to the nearest integer...then dividing by 100 again to get the decimal point.

Give this a try.