Math.abs() Limit the amount of deimals

CrunchyToast

I have scoured the internet and I haven't found a solution that really works for me, yet.

var tv = Length * Type;

if (tv < 0) 
    {
    cForm.voltage.value = "-" + Math.abs(tv) + " V";
    }
else...

Some of the calculations with these two numbers come out to about the 15th decimal for some reason. I would like to limit the decimal amount that is returned, and NOT allow the number to round up or down. On a calculator it only comes out to about the third decimal, but Math.abs() brings it too far out.

.toFixed() Doesn't work for me because if the number only has 2 decimals it will add additional zeros at the end. I only want to display up to the fourth if it is calculated.

TbWill4321

Just expanding on @goto-0 s comment, with the correct # of decimal places.

var tv = Length * Type;

if (tv < 0) 
    {
        cForm.voltage.value = "-" + (Math.round(Math.abs(tv) * 10000) / 10000) + " V";
    }
else...

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Math.abs()deimalsの量を制限する

分類Dev

How To Limit The Amount Of Notifications

分類Dev

HashMap stream with criteria Math.abs(double)

分類Dev

HashMap stream with criteria Math.abs(double)

分類Dev

Limit amount of parameters in query string

分類Dev

LIMIT amount of rows fetched by JOIN

分類Dev

Math.abs(a-b)-Math.abs(c-d)のより高速な実装?

分類Dev

Math.Pow(10、Math.Abs(1))は10に等しいですか?

分類Dev

How to limit the amount of characters in a Lua string

分類Dev

How to limit the amount of bullets in a JavaScript Game?

分類Dev

基準がMath.abs(double)のHashMapストリーム

分類Dev

Java Math.absランダムvs. nextInt()

分類Dev

How to limit amount of pods with attached managed disks per node

分類Dev

Limit the amount of times font size can be increased and decreased

分類Dev

Math.absがInteger.Min_VALUEに対して誤った値を返す

分類Dev

Math.abs()を使用せずに数値の絶対値を見つける

分類Dev

Linq.Expressions.ExpressionでのMath.Absの使用-動的クエリの作成

分類Dev

'min_amount' AND'set_customer_limit 'のPayPalボタン

分類Dev

How to limit the amount of data for each user in a MySQL table and automatically delete the oldest data

分類Dev

JavaのMath.abs(int型)の最適化、なぜこのコードは6倍倍遅く?

分類Dev

Java関数型プログラミングrandom int stream math absが機能しない

分類Dev

なぜsqrt()とabs()がmath.hやstdlib.hを含めずにCプログラムで機能するのですか?

分類Dev

Why is `abs()` implemented differently?

分類Dev

AbsとminBound

分類Dev

java.Mathのようなクラスを反映する方法(Math.abs()などのようなパラメーターのタイプの関数を抽出したい)

分類Dev

Python-absとfabs

分類Dev

Python-absとfabs

分類Dev

Abs beginner Haskell pattern matching

分類Dev

数値がJavaの範囲内にあるかどうかをどのようにして見つけますか?Math.abs(num1-num2)<= inRangeの問題

Related 関連記事

  1. 1

    Math.abs()deimalsの量を制限する

  2. 2

    How To Limit The Amount Of Notifications

  3. 3

    HashMap stream with criteria Math.abs(double)

  4. 4

    HashMap stream with criteria Math.abs(double)

  5. 5

    Limit amount of parameters in query string

  6. 6

    LIMIT amount of rows fetched by JOIN

  7. 7

    Math.abs(a-b)-Math.abs(c-d)のより高速な実装?

  8. 8

    Math.Pow(10、Math.Abs(1))は10に等しいですか?

  9. 9

    How to limit the amount of characters in a Lua string

  10. 10

    How to limit the amount of bullets in a JavaScript Game?

  11. 11

    基準がMath.abs(double)のHashMapストリーム

  12. 12

    Java Math.absランダムvs. nextInt()

  13. 13

    How to limit amount of pods with attached managed disks per node

  14. 14

    Limit the amount of times font size can be increased and decreased

  15. 15

    Math.absがInteger.Min_VALUEに対して誤った値を返す

  16. 16

    Math.abs()を使用せずに数値の絶対値を見つける

  17. 17

    Linq.Expressions.ExpressionでのMath.Absの使用-動的クエリの作成

  18. 18

    'min_amount' AND'set_customer_limit 'のPayPalボタン

  19. 19

    How to limit the amount of data for each user in a MySQL table and automatically delete the oldest data

  20. 20

    JavaのMath.abs(int型)の最適化、なぜこのコードは6倍倍遅く?

  21. 21

    Java関数型プログラミングrandom int stream math absが機能しない

  22. 22

    なぜsqrt()とabs()がmath.hやstdlib.hを含めずにCプログラムで機能するのですか?

  23. 23

    Why is `abs()` implemented differently?

  24. 24

    AbsとminBound

  25. 25

    java.Mathのようなクラスを反映する方法(Math.abs()などのようなパラメーターのタイプの関数を抽出したい)

  26. 26

    Python-absとfabs

  27. 27

    Python-absとfabs

  28. 28

    Abs beginner Haskell pattern matching

  29. 29

    数値がJavaの範囲内にあるかどうかをどのようにして見つけますか?Math.abs(num1-num2)<= inRangeの問題

ホットタグ

アーカイブ