Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Square Root Function Is Not Rounding To The Decimal Point I Want To
- -Tintinnabulation-
-
Scratcher
36 posts
Square Root Function Is Not Rounding To The Decimal Point I Want To
Hi,
Im Making A Calculator And I Want The Square Root Function To Choose The Decimal Point I Want to!
Is Rounding More Than 6 Digits Of The Decimal Point Will Round To 6 Digits But I Want More!
Here is My Script: (Decimal = 10,000,000 Or 10M, 1 Followed 7 Zeros = 7 Decimal Places)
For Example, Sqrt(2) Rounded To 7 Decimal Places = 1.4142136
but it keeps giving me 6 decimal places! (1.414214)
Im Making A Calculator And I Want The Square Root Function To Choose The Decimal Point I Want to!
Is Rounding More Than 6 Digits Of The Decimal Point Will Round To 6 Digits But I Want More!
Here is My Script: (Decimal = 10,000,000 Or 10M, 1 Followed 7 Zeros = 7 Decimal Places)
when this sprite clicked
set [Number 3 v] to ([Sqrt v] of (Number)::operators)
set [Number v] to ((round ((Number 3) * (Decimal))) / (Decimal))
For Example, Sqrt(2) Rounded To 7 Decimal Places = 1.4142136
but it keeps giving me 6 decimal places! (1.414214)
Last edited by -Tintinnabulation- (Jan. 13, 2025 16:04:03)
- Cool_Dude2022
-
Scratcher
500+ posts
Square Root Function Is Not Rounding To The Decimal Point I Want To
Hi,
Im Making A Calculator And I Want The Square Root Function To Choose The Decimal Point I Want to!
Is Rounding More Than 6 Digits Of The Decimal Point Will Round To 6 Digits But I Want More!
Here is My Script: (Decimal = 10,000,000 Or 10M, 1 Followed 7 Zeros = 7 Decimal Places)when this sprite clicked
set [Number 3 v] to ([Sqrt v] of (Number)::operators)
set [Number v] to ((round ((Number 3) * (Decimal))) / (Decimal))
For Example, Sqrt(2) Rounded To 7 Decimal Places = 1.4142136
but it keeps giving me 6 decimal places! (1.414214)
This should fix it:
(join ([sqrt v] of (2)::operators) [])
Here's an example: https://scratch.mit.edu/projects/1119690931/editor/
- -Tintinnabulation-
-
Scratcher
36 posts
Square Root Function Is Not Rounding To The Decimal Point I Want To
Hi,
Im Making A Calculator And I Want The Square Root Function To Choose The Decimal Point I Want to!
Is Rounding More Than 6 Digits Of The Decimal Point Will Round To 6 Digits But I Want More!
Here is My Script: (Decimal = 10,000,000 Or 10M, 1 Followed 7 Zeros = 7 Decimal Places)when this sprite clicked
set [Number 3 v] to ([Sqrt v] of (Number)::operators)
set [Number v] to ((round ((Number 3) * (Decimal))) / (Decimal))
For Example, Sqrt(2) Rounded To 7 Decimal Places = 1.4142136
but it keeps giving me 6 decimal places! (1.414214)
This should fix it:(join ([sqrt v] of (2)::operators) [])
Here's an example: https://scratch.mit.edu/projects/1119690931/editor/
I Meant The Player Can Be Able To Change The Number Of Digits In The Decimal, Is There Any Way To Go Past 6 Digits And The Player Can Be Able To Change The Amount Of Digits In The Decimal Point?
For Example (Decimal Value = 3): “sqrt(55) = 7.42”
(There Is Another Variable Called Decimal Value, Decimal is 1 followed by how many 0 you want the decimal point to be)
Last edited by -Tintinnabulation- (Jan. 14, 2025 07:29:07)
- deck26
-
Scratcher
1000+ posts
Square Root Function Is Not Rounding To The Decimal Point I Want To
If you want no more decimal places than Scratch will normally give (ie fewer or the same) you can easily round to the required number of decimal places using (round (N * value)) / N where N is the appropriate power of 10. You may have to add trailing zeroes which would normally be removed - either using join value ‘0’ OR use a basic text engine method to display the value if you actually always want to display the same number of digits after the decimal point.
However if you want more accuracy than Scratch is giving you you'll need to create your own maths operators which is a lot more work. Scratch, like other languages, will only cope with limited precision which is good enough for most purposes.
However if you want more accuracy than Scratch is giving you you'll need to create your own maths operators which is a lot more work. Scratch, like other languages, will only cope with limited precision which is good enough for most purposes.
- Discussion Forums
- » Help with Scripts
-
» Square Root Function Is Not Rounding To The Decimal Point I Want To


