How can I set a format for each column when displaying my table? - matlab

My table only contains numerical data. I have format set to long and all of the variables are of that type. How can tell MATLAB to display each column differently? i.e column 1 as type long with 15 decimal digit precision, column 2 in scientific notation with 4 decimal precision, etc?

Related

how to the get the Pentaho table values with Decimal

I am using Pentaho-code I am round the queries values as decimal but getting some colums values not decimal
table output:
NORMAL (06:00--17:00) 3 14341.54 43024.62
OFF_PEAK (22:00--06:00) 3 7002.39 21007.170000000002
PEAK (17:00--22:00) 3 9362.95 28088.850000000002
required output
NORMAL (06:00--17:00) 3 14341.54 43024.62
OFF_PEAK (22:00--06:00) 3 7002.39 21007.17
PEAK (17:00--22:00) 3 9362.95 28088.85
Column formats %.2f will definitely work to show 2 decimal point. You just need to be define column formats for every column. For string you need to define %s, for only real digit use %d, and to get 2 decimal you need to define %.2f etc.
You can have a look in my sample image for correct configuration-

Concatenate Negative Number and String in SSRS

I'm having a trouble in concatenating the Negative numbers and Strings. I've successfully display the negative numbers with parenthesis (ex. (3)) but when I add the string to it the format of number becomes -3 again. This is my expression:
=Cint(Fields!UNT_TAKEN.Value) & " UNITS"
It returns me with this value -3 UNITS
But I want to return (3) UNITS
Thank you in advance.
If UNIT_TAKEN is already a number then you can just set the format property of the cell/textbox to
0 Units;(0) Units
If UNIT_TAKEN is a string then set the value expression of the cell/textbox to
=FORMAT(CINT(Fields!UNIT_TAKEN.Value),"0 Units;(0) Units")
Below I created a dataset with both a numeric and string version of seven numbers. The table below shows the actual values and the formatted values as above.

Postgres Custom float type that is always truncated to 2 decimals after point

Can I generate a custom data type in postgres that everytime I insert or update a float into it it is truncate to 2 decimals after dot.
create table money(
formatted moneys_type
);
insert into money values (30.122323213);
Select * from money;
Returns
30.12
Update I didn't use numeric or decimal because they round up when 1.999 => 2
See documentation on Numeric Types / Arbitrary Precision Numbers.
The precision of a numeric is the total count of significant digits in
the whole number, that is, the number of digits to both sides of the
decimal point. The scale of a numeric is the count of decimal digits
in the fractional part, to the right of the decimal point. So the
number 23.5141 has a precision of 6 and a scale of 4. Integers can be
considered to have a scale of zero.
...
To declare a column of type numeric use the syntax:
NUMERIC(precision, scale)
The maximum allowed precision when explicitly specified in the type declaration is 1000.
So you can use
NUMERIC(1000, 2)

length and precision issue in Postgres

I'm using postgres sql I need 12 digits and after decimal I need only 6 digits what length & Precision should I give in columns.what datatype shold I give to cloumn.
I tried numeric as a datatype and length I give to column is 12 and precision is 6.
If you need 12 digits before the decimal and 6 digits after, you need numeric(18,6)
Quote from the manual
The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point
(Emphasis mine)
So the first number (precision) in the type definition is the total number of digits. The second one is the number of decimal digits.
If you specify numeric(12,6) you have a total of 12 digits and 6 decimal digits, which leaves you only 6 digits for the digits to the left of the decimal. Therefor you need numeric(18,6)

How to set precision and scale in ALTER TABLE

I have working code with PostgreSQL 9.3:
ALTER TABLE meter_data ALTER COLUMN w3pht TYPE float USING (w3pht::float);
but don't know how to set precision and scale.
The type float does not have precision and scale. Use numeric(precision, scale) instead if you need that.
Per documentation:
The data types real and double precision are inexact, variable-precision numeric types.
For your given example:
ALTER TABLE meter_data ALTER COLUMN w3pht TYPE numeric(15,2)
USING w3pht::numeric(15,2) -- may or may not be required
The manual:
A USING clause must be provided if there is no implicit or assignment cast from old to new type.
Example: if the old data type is text, you need the USING clause. If it's float, you don't.
As per PostgreSQL documentation, you can select the minimum number for the floating point numbers using syntax float(n) where n is the minimum number of binary digits, up to 53.
However, to store decimal values at all, use numeric(precision, scale) or its synonym decimal(precision, scale) but notice that these are hard limits; according to the documentation:
If the scale of a value to be stored is greater than the declared
scale of the column, the system will round the value to the specified
number of fractional digits. Then, if the number of digits to the left
of the decimal point exceeds the declared precision minus the declared
scale, an error is raised.
Thus your alter table could be:
ALTER TABLE meter_data
ALTER COLUMN w3pht TYPE numeric(10, 2)
USING (w3pht::numeric(10, 2));
for 2 digits right of decimal point and 10 total digits. However if you do not
need to specify limits, simple numeric will allow "up to 131072 digits before the decimal point; up to 16383 digits after".