# Typeof msg.payload === 'number' throws exception

**URL:** <https://discourse.nodered.org/t/typeof-msg-payload-number-throws-exception/828>\
**Category:** General\
**Created:** [15 June 2018 06:11 UTC](https://discourse.nodered.org/t/typeof-msg-payload-number-throws-exception/828 "2018-06-15T06:11:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![naser300](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@naser300](https://discourse.nodered.org/u/naser300)\
**Post date:** [15 June 2018 06:11 UTC](https://discourse.nodered.org/t/typeof-msg-payload-number-throws-exception/828/1 "2018-06-15T06:11:13Z")

</div>

Hi,

I tried to convert a msg.payload to return round value of the number. But the function does not return the number.

The js code is here:

```auto
module.exports = function(RED) {
   function MathOPeration(config) {
       RED.nodes.createNode(this,config);
       var node = this;
	   this.operation = config.operation;
       this.on('input', function(msg) {
		   if (typeof (msg.payload) === 'number'){
			   if(node.operation === "floor"){
				   //var x = parseInt(node.operation);
				   //var a = Math.floor(x);
				   //msg.payload = msg.payload.a;
				   // msg.payload = Number(msg.payload);
					msg.payload = msg.payload.Math.floor(msg.payload);
			   }
			   else if(node.operation === "lower"){
				   msg.payload = msg.payload.toLowerCase();
				 
			   }
			   else if (node.operation === "round"){
		   msg.payload = msg.payload.Math.round(node.operation);
		   
			   }
			   else if (node.operation === "sqrt"){
					var y = parseInt(node.operation);
				    var c = Math.sqrt(y);
				   msg.payload = msg.payload.c;
		   
			   }
           node.send(msg);
		   }else{
			   node.error("Payload not number",msg);
		   }

```

While in debug the return shows undefined. How can I get the floor value?

Regards.

Abu Naser Mohammad Muinuddin

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [15 June 2018 06:25 UTC](https://discourse.nodered.org/t/typeof-msg-payload-number-throws-exception/828/2 "2018-06-15T06:25:47Z")

</div>

There are a few places in your code where you use `msg.operation` expecting it to contain the number, but it contains the name of the operation.

As this is the assignment from the Node-RED Coursera course, please use the Course forum for questions. We cannot complete the assignment for you.

Nick
