Rounding to two decimal places in Octave - octave

After a calculation I got 32.073 .I need it to round to 32.07 using Octave.Please can somebody help me?

You can do:
res = round(100 * 37.073) / 100

you could use the C style printf format.
sprintf("%.2f", 32.073)

You can just type format bank in the begining

Related

Converting a decimal number x > 1 with n decimals to binary (for example: 70,5)

For homework I am to convert a decimal number to binary. This is usually pretty easy, but I have no idea how to it with a number like 70,5.
I know that there is the multiplication algorithm for x < 1, but here, x > 1. I was thinking about maybe writing 70,5 as a sum of numbers that are < 1, then find the binary expressions of these and take the sum. But I'm not sure this is the right approach.
Any ideas?
I found out how to do it!! Just find the binary of 70 (1000110), the binary of .5 (.1) and put them together like 1000110.1 :D

Scilab how to replace a comma with a dot in an matrix

May I ask for some advice, please?
I have for homework process data from file which has this structure:
"Time;Track;Force
s;mm;N
0,020;0,253;0,060
0,040;0,320;0,030
0,060;0,387;0,060
0,080;0,453;0,060
0,100;0,520;-0,000
0,120;0,587;0,030
0,140;0,654;0,030
0,160;0,721;-0,000
0,180;0,787;0,030
0,200;0,854;0,030
0,220;0,921;0,030
0,240;0,988;-0,000"
To load the data to matrix I use this command:
csvRead("Pene_1.txt",[';'],[],"string")
However my issue with this, is that the dates I would need in double because I will need to do some calculate with them, but in Europe a decimal point is used as the data separator instead of a decimal point. I would need to replace all of these decimal commas with decimal dots throughout the matrix. Please does anyone how to do it? Thanks you very much :)
by the way there I put whole file :)
http://leteckaposta.cz/859703762
Use csvRead("Pene_1.txt",';',',',"string") the third parameter ',' defines the decimal separator.

How can i add two real numbers without use add.s/add.d in mips?

I tried searching around the web but there doesn't seem to be any hope.
please help me? Thanks.
You can substitute subtraction: A + B ==> A - (-B)

SQL avg then trailing numbers

I'm trying to get the average number, and then remove the trailing, pointless zeros afterwards, (new to SQL) but I can't understand why it wont remove them, do I have the wrong idea??
So far I have;
SELECT total,
AVG(total(TRUNCATE(total/1,2))
I think you are looking for cast as below.
select cast(17.800000 as dec(3,1))
Result:
val
----
17.8
so you query will be
SELECT total, cast(AVG(total) as dec(3,1))
considering you just need 2 digit before . If you need more digits, you can adjust it accordingly.
DEMO
Assuming you are using SQL Server then you can cast the answer to a decimal with one decimal point:
select cast(avg(total) as decimal(9,1))
This SQLFiddle shows it: link
SELECT
TRUNCATE(AVG(myFloat), 2),
AVG(myFloat),
ROUND(AVG(myFloat), 2)
FROM docs
You should probably use ROUND instead of TRUNCATE.
The stuff after the decimal is odd because of floating point math, and there are occasions where floating point math is internally calculated as .009999999 instead of .01000000000
I believe these answers that use a CAST may have the same truncation problem.
You simply want to avoid casting or truncation when you are removing the decimal places beyond what you're interested in. Be explicit in what you are doing and less mistakes will pop up later.

Mysql: money and floats

What float do I need to store such sums like these: $1,200,000, $1,000, and $14.56 ? ($ dosn't count; it will be removed)
Don't. Store as an int and multiply/divide by 100. e.g. Store 14.56 as 1456, but /100 when displaying. Floating point for storing currency is just asking for rounding problems.
Try DECIMAL. See http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html