NManteufel Posted September 17 Share Posted September 17 In my Javascript script, I am trying to truncate an average to three decimal points, but Math.floor(average*1000)/1000; is not working. How can I truncate "average" to three decimal points? Link to comment Share on other sites More sharing options...
0 attila Posted September 17 Share Posted September 17 Hi @NManteufel This should work if average is a number. Link to comment Share on other sites More sharing options...
0 NManteufel Posted September 17 Author Share Posted September 17 (edited) It's not working. This is the full example, I am using the GPIO to switch a relay (HE3621A0500) and the scope to read the signal. StaticIO.Channel0.DIO[0].text = "1"; // VDD_2V9 CONNECTED wait(1) // Allow to stabilize Scope.single(); if(!Scope.wait()) throw "Stopped"; var average = 0; var data = Scope.Channel1.data; data.forEach(function(sample){average += sample;}) average /= data.length; Math.floor(average * 1000) / 1000; print("VDD_2V9\t\t\tP4\t\t"+average+" V"); StaticIO.Channel0.DIO[0].text = "0"; // VDD_2V9 DISCONNECTED Edited September 17 by NManteufel Link to comment Share on other sites More sharing options...
0 attila Posted September 17 Share Posted September 17 The truncated values is not use or assigned to anything. To print it: print("VDD_2V9\t\t\tP4\t\t"+(floor(average * 1000) / 1000)+" V"); NManteufel 1 Link to comment Share on other sites More sharing options...
0 NManteufel Posted September 17 Author Share Posted September 17 Thanks, that solved my problem. attila 1 Link to comment Share on other sites More sharing options...
Question
NManteufel
In my Javascript script, I am trying to truncate an average to three decimal points, but
is not working.
How can I truncate "average" to three decimal points?
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now