The attempt to convert the value "NaN" to a number (data type number) at the specified path "markupPercentage" was unsuccessful

When I try to use Excel to update products, I encounter an error related to the presence of NaN. Here is the specific error message:

CastError: Cast to Number failed for value "NaN" (type number) at path "markupPercentage"      
  messageFormat: undefined,
  stringValue: '"NaN"',
  kind: 'Number',
  value: NaN,
  path: 'markupPercentage',
  reason: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert.ok(!isNaN(val))

Function

export function roundNumber(value: any, numberOfDecimals: number = 2): number {
  if (value) {
    if (!isNaN(value)) {
      switch (numberOfDecimals) {
        case 0:
          return Math.round(value * 1) / 1
        case 1:
          return Math.round(value * 10) / 10
        case 2:
          return Math.round(value * 100) / 100
        case 3:
          return Math.round(value * 1000) / 1000
        case 4:
          return Math.round(value * 10000) / 10000
        case 5:
          return Math.round(value * 100000) / 100000
        case 6:
          return Math.round(value * 1000000) / 1000000
        default:
          return Math.round(value * 100) / 100
      }
    } else {
      return parseFloat(value.toFixed(numberOfDecimals))
    }
  } else {
    if (value === 0) {
      return 0
    }
  }
}

Code

case 'markupPercentage':
   article.markupPercentage += percentage
   article.markupPercentage = roundNumber(article.markupPercentage, decimal)
   article.markupPrice = roundNumber((article.costPrice * article.markupPercentage) / 100)
   article.salePrice = article.costPrice + article.markupPrice
break

Model

markupPercentage: {type: Number, default: 0},

Answer â„–1

When your if-statement results in a NaN for the value, you will reach this section known as the else block:

} else {
  return parseFloat(value.toFixed(numberOfDecimals))
}

This is where the parseFloat function encounters difficulty parsing the NaN value.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

transferring id values between controllers in angularJS

How can I pass an id from one controller to another in Angular? I have a select menu that allows for selecting a tournament, and upon selection, I want to retrieve the tournament’s _id value in a different controller to query data. Being new to Angular ...

What steps do I need to follow in order to incorporate and utilize an npm package within my Astro component

I have been working on integrating KeenSlider into my project by installing it from npm. However, I am encountering an error message that says Uncaught ReferenceError: KeenSlider is not defined whenever I try to use the package in my Astro component. Belo ...

npm: Import a package from a GitHub repository that does not belong to me

I have encountered a package that I need for my project, but it is not available in npm. I am considering the option of uploading the package to npm myself. However, I am unsure if this is ethically or legally acceptable. What is your opinion on this mat ...

What is the best way to merge imported types from a relative path?

In my TypeScript project, I am utilizing custom typings by importing them into my .ts modules with the following import statement: import { MyCoolInterface } from './types' However, when I compile my project using tsc, I encounter an issue wher ...

Acquire $(this) when the onclick event is activated

Usually, I rely on a jQuery event handler for CSS styling. However, today I decided to experiment with using the HTML event attribute instead. Below is the code that I used: $('.navBtn').on('click', function() { var length = $(th ...

Incorporating JSON into a Yahoo! widget

Help! I was reading the Yahoo! Widgets spec and it mentioned that I can parse JSON objects using JSON.parse(). So, being curious, I tried it out with this code snippet... var parsed = JSON.parse('{"key": "value"}'); console.log(parsed); for ( ...

Utilizing an SSL certification (pem file) within JavaScript

Currently in the process of developing a program to extract data from the FAA's AIDAP database. I received a security certificate in the form of a .p12 file, which I have successfully converted into a .pem file. However, I am encountering difficulties ...

A guide to setting up a compound index in MongoDB using the Java driver

I am attempting to establish a compound index on both the Age and Name fields in MongoDB using the Java driver. Below is the syntax I have been working with: coll.ensureIndex(new BasicDBObject("Age", 1),new BasicDBObject("Name", -1)); List <DBObject& ...

Pass information to a PHP file using JavaScript when the form is submitted

Essentially, I am looking to extract values from various inputs and spans using JavaScript when the submit input is clicked. These values will then be sent to PHP using $post in order to ultimately send them via email. Previously, I tested replacing all of ...

Selenium server is not running and causing a connection refusal

Recently, I took over a project at work that lacks any documentation. The project is built on sails.js and includes a small number of unit tests along with an end-to-end test. Unfortunately, when attempting to execute the end-to-end test using grunt, the ...

When invoked, a Javascript Object comes back empty

My code snippet: const channels = fauna.paginate(q.Match(q.Index("channels"), "true")) // Query FaunaDB database for channel list => create constant called users containing results const channelList = channels.each(function (page) { ...

Executing a PHP script to initiate a ping transmission

I have a project to complete for my university involving the development of a simple application. However, I lack experience in this area and am unsure how to proceed. The objective is straightforward: I want to send ping requests to 50 IP addresses at t ...

What is the best way to choose a specific row with Enzyme?

We have chosen Jest for doing UI Test-Driven Development on our React application. Our component rendering structure looks like this: <Div> <Row> </Row> <ROW> <Row> <ROW> <Link> <Link> ...

Determine image size (pre-upload)

One of the requirements for a project I am working on is to verify the dimensions (width and height) of images before uploading them. I have outlined 3 key checkpoints: 1. If the dimensions are less than 600 X 600 pixels, the upload should be rejected. ...

Difficulty linking the front to the rear

I'm facing an issue where my front-end doesn't seem to be connecting with the back-end. Despite receiving a token from the back-end via Postman, I encounter an error when trying to log in that reads "Cannot POST / Admin" - noting that 'admin ...

Retrieve the appended element's object

I am currently facing an issue with accessing elements that are automatically added by a library in my code. In my HTML, I have the following line: <div class="bonds" id="original" style="display:block;"></div> The library appends some elemen ...

Is there a quick way to use AJAX in Rails?

By using the remote:true attribute on a form and responding from the controller with :js, Rails is instructed to run a specific javascript file. For instance, when deleting a user, you would have the User controller with the Destroy action. Then, you woul ...

What is the process for extracting a nested document from an array of documents in mongodb?

I am currently facing a challenge in my project where I need to remove a nested objects array within a document. The specific scenario involves searching for the days on which an event will be held, based on its event ID. const { eventid, typesOfTicketId ...

Encountering an error of undefined upon submission of a form while utilizing ng

Sorry if this question has been asked before, but I've searched extensively online and still can't find a solution. I'm new to Angular and TypeScript and I may be overlooking something simple, but I can't get it to work. Any help would ...

What measures can I take to store data for a website user?

Check out my code on this website: If not, here is the HTML and JavaScript snippets: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <meta name="viewport" content="width=device-width, initial-scale=1.0"> ...