we have been experimenting with a small calculator project and ran into an interesting question about calculation logic.

For things like unit conversions, percentages, rounding, and derived values, do you normally keep everything in JavaScript, or do you prefer to handle some of the calculations server-side?

we are especially interested in how people structure the logic so it stays easy to test and doesn’t get mixed too heavily with the UI.

How do you usually approach this in your own projects?

rproffitt commented: Answering your own question just to spam your URL +0

We did keep the core calculation logic separate from the UI and run the calculations client-side for a small tool like this. It keeps the interface responsive and avoids unnecessary server requests.

For example, we did have pure functions for unit conversion, percentages, rounding, and derived values, then let the UI simply pass the inputs and display the results. That also makes the calculation functions much easier to test independently.

we are using a similar approach in a small construction calculator project, where inputs such as dimensions, density, and bitumen content are combined to produce the final quantities.

we did only move the calculations server-side if there were sensitive business rules, very complex processing, or a need to guarantee that the calculation logic couldn’t be altered in the browser.

commented: Answering your own question just to spam your URL -4
commented: Promotional -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.