Round Number - CodelessBot

What Does This Plugin Do?

BETA
This plugin will round a number to a specific number of decimal places.

Level of Difficulty: Easy

Compatibility: Chatfuel, ManyChat

Plugin Request URL
  • Chatfuel: https://api.codelessbot.com/v1/chatfuel/number/round?accesskey={{cbot_accesskey}}&secretkey={{cbot_secretkey}}
  • ManyChat: https://api.codelessbot.com/v1/manychat/number/round?accesskey=YOURACCESSKEY&secretkey=YOURACCESSKEY

Example Use Cases

Round to nearest cents

Round a number to the nearest dollar or cents.

Round score to nearest number

Get rid of any unnecessary decimals before sending the score to the user

Display Trailing Zeros

Use this plugin to force Chatfuel/ManyChat to display zeros at the end of a number!

How-To Setup the Plugin

Follow the 3 Simple Steps...or Login to CodelessBot to access the Plugin Wizard!

Step 1. Download & Install the Quick-Start Plugin Template

Login to CodelessBot, navigate to Templates on the sidebar and download the Quick-Start Template. Follow the prompt to install the Template. Next, you'll need to create a copy of the template for this specific plugin. See and follow the instructions below.

(If you've already install the Quick Start Template and created a copy of the plugin template - skip this step!

Chatfuel Instructions

a. From your Chatfuel dashboard, open the new bot called "JSON API Tutorial & CodelessBot Template" 

b. Find the group containing the name of this plugin.

c. Click on the arrow next to the plugin name to clone this group and blocks from the template into your own Chatfuel Bot.

d. Navigate back to the Chatfuel Dashboard

e. Open your Bot and find the new plugin group that you just cloned. 

f. Open the new Plugin block and enter in your CodelessBot access key and secret key.

Tip: Rename the plugin block to something more meaningful. For more details, refer to the Getting Started Guide.

ManyChat Instructions

After you download and installed the Quick Start Template...

  1. From the ManyChat sidebar, click on the Flows"
  2. Open the folder "CodelessBot Templates"
  3. Find the flow containing the name of this plugin. 
  4. Create a copy by click on the three dots icon on the right
  5. Then click on duplicate
  6. Feel free to rename this new flow and move it to a different folder
  7. Open up the flow and click on the "Starting Step" to modify the information you'll be sending to CodelessBot

For more details, refer to the Getting Started Guide.

Step 2. Send information to CodelessBot

To quickly do this, use the Plugin Wizard to answer a few questions. It'll then generate the code with the information below for you to copy and paste into your bot.

cbot_number

The number you want to round.

cbot_decimals

The number of decimal places you want to round to.

More Detail

This number must be between -10 and 5.

A positive number rounds to the right of the decimal (eg. 155.357 rounded to 2 decimals is 155.36)

A negative number rounds to the left of the decimal (eg. 155.357 rounded to -2 decimals is 200)

Chatfuel Instructions
  1. In this plugin block, scroll down to the "JSON API" card
  2. Copy and paste the code from the Plugin Wizard into the textbox. (Or you can enter the correct value by referring to the descriptions above.)

Tip: Make sure the "Send as" is set to JSON. Not URL encoded or Full JSON Profile.

ManyChat Instructions

a. Click over to the "Body" tab in this external request 

b. Next, copy and paste the code from the Plugin Wizard into the "Request Body". (Or you can enter the correct value by referring to the descriptions above.)

c. If there are any "Replace With placeholder" in the code, you'll need to replace them with the correct matching custom field by clicking on "Add a Variable".

d. To check if you set this up correctly, click on "Test the Request" on the right and you should get a success "200 OK" response

e. Click on the blue "Save" button

Step 3. CodelessBot will reply with the "answer"

CodelessBot will reply back with the following information:

cbot_rsp

The rounded number as text (meaning, any trailing zeros will appear).

Chatfuel Instructions

After the JSON API card, you can add additional Chatfuel cards to:

  1. Send a message to the user with the result
  2. Add a new card "Go To Block" with a condition to redirect users to a different blocks depending on the result

Note: These are just some ideas. You are not limited by the 2 ideas above.

ManyChat Instructions

Finally, to save and make use of the results, you'll need to save the answer(s) from the CodelessBot to ManyChat custom field(s). To do this:

a. Click over to the "Response mapping" tab.

b. All the answer(s) are already listed for you under the first column "JSONPath". (For more detail about each one, see description above).

For each answer, select the ManyChat custom field you want to use to store the value from CodelessBot. Feel free to delete any that you don't need.

c. Click on "Save" when you're done. After this external request step, you can add a next step where you're:

  • Sending a message to share the results with users
  • Add a new Condition step to redirect users to a different step or flow depending on the result

More Information

FAQs

1. Is there a min/max value for the number?

The plugin was NOT designed for scientific use. It was designed for common, everyday rounding scenarios. The number should not exceed +/- 9,007,199,254,740,991, the decimal precision of the input number should not exceed 5 decimal places, and the numbers should each not exceed 12 significant digits. Numbers beyond these specifications may lead to unintended rounding and interpretation of the number.

2. I'm not sure what I should enter for cbot_decimals. Can you give me some more examples?

Here’s a few example. Suppose you want to round the number 1234.579

  • If cbot_decimal is -2, then the rounded result will be 1200
  • If cbot_decimal is -1, then the rounded result will be 1230
  • If cbot_decimal is 0, then the rounded result will be 1235
  • If cbot_decimal is 1, then the rounded result will be 1235.6
  • If cbot_decimal is 2, then the rounded result will be 1235.58

 

3. In Chatfuel, how do I send or round a number with more than 2 decimals spaces?

You cannot. Unfortunately, any number within Chatfuel will immediately be rounded to 2 decimal places. For example, if you set cbot_number = 5.129 and immediately send a message containing the value of cbot_number, you’ll see a message with the value 5.13 – even if you did not use this rounding plugin yet!

Also note:

  • If you try to send the value 5.129 to CodelessBot for rounding, you are actually sending 5.13
  • If you try to round the value 5.1294 to 3 decimal places, you will receive the answer 5.130 and not 5.129

4. Can I perform math operations with the rounded number from CodelessBot?

Yes! With the rounded number, you can perform math operations in Chatfuel and in ManyChat using custom formulas.

The reason why we return the cbot_rsp as text, is so that any trailing zeros will appear. Otherwise, a number 5.50 will be displayed as 5.5

Enhance Your Bot with CodelessBot

CodelessBot plans start from $18/month