# How can i round a number?

Hello, I have a command which when putting a number it multiplies it with another number, the problem is that when it solves the operation all the decimals come out, my question is, how could I reduce the decimals to 2? the command is as follows:

\$(user) mide \$(eval \$(touser)*(1/1.51)) Reis de altura

The command is for convert certain units given to another unit system, I am new to creating commands so it has several errors. For example, if I put some number it will operate it (with all the decimals, problem # 1), but if I put only the command it will name the user who put the command together with the accompanying text “Reis de altura” (problem # 2)

Mainly I would like to fix the problem of decimals so that it shows the result with 2 decimals, but I would also like to solve problem # 2 by putting a condition that if the characters given are not numbers, put some text that explains how to use the command. If anyone know how to solve problem # 1 or both would greatly appreciate it

I think this should do what you want:

``````\$(eval n=parseFloat(`\$(1)`);c=Math.round(n*(1/1.51)*100)/100;isNaN(n)?`Explanation of how to use`:`\$(user) mide \${c} Reis de altura`)
``````

I get: ParseFloat is not defined

Sorry for taking a long time to respond, i was trying to fix it, but i’m not very good at programming >.<

Sorry about that it’s supposed to be lowercase p I thought I changed it but apparently not I edited the code above it should work now.

Perfect, you are a genius, thank you very much.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.