How to save a rounded decimal value to a SQL database table

  • 15 February 2022
  • 0 replies
  • 61 views

Badge +5

Topic

This article will cover how to save a rounded decimal value to a SQL database table. 

 

For SmartBox SmartObjects, this can be done by specifying the Decimal Places on the Decimal property as per the image below:

18945i5310BEAB70AA1765.png

 

This setting does not apply to SQL SmartObjects. If you type in a value of "4.555", this will be saved as "4.55" on the database. In order to save the desired rounded value (eg. "4.56"), you will need to create an Expression that calls the Round Up Mathematical Inline Function.

 

Instructions

In this example, the Price Text Box holds the decimal value:

18946iE3C1DE6B067D68B9.png

 

  1. Create a new Expression.
  2. Use the Round Up inline function found under Operators > Mathematical and set it up as per the image below. The second parameter (eg. 2) depends on the scale (number of decimal places) required:18947i1D78358D25DE5671.png

     

  3. Click on OK to save the Expression.
  4. Go to the Rules tab and open the rule which calls the SQL SmartObject to save the value to your database.
  5. Before the Create/Update method is called, add a transfer data action:18948iEFA46A353A9046E1.png

     

  6. Map the RoundUp expression created to the Price Text Box: 18949i0929DBB9978F883D.png

 

 

Test

    1. Run the view and type in 4.555 on the Price Text Box:18953i94B8CAB898377ED4.png

       

    2. Click outside the Price Text Box so it changes to 4.56:18952i896E160B7F369ECF.png

       

    3. Click on the Create button and the rounded off value should be stored in the database:

18950i102FC77AA47743C7.png

 

 

Related Links


0 replies

Be the first to reply!

Reply