22 Temmuz 2013 Pazartesi

Unity3d - Round double / float values

Hi,
To be able to round the values in unity csharp you need the code below:


float rawValue = 5.521f;
rawValue = Mathf.Round(rawvalue * 100f) / 100f);
//it should return 5.5



In order to increase decimals, just use 1000 or 10000 etc.

8 Temmuz 2013 Pazartesi

MS SQL Adding Unique Column / Columns

Hi,
I always keep forgetting this sql command,
if you have a table and you want to create unique columns use following statement:

ALTER TABLE dbo.tablename ADD CONSTRAINT constraintName UNIQUE (col1, col2, col3)

like:
ALTER TABLE dbo.User ADD CONSTRAINT uqUPE UNIQUE (username, phone, email)

This prevents you to insert a row with the same username AND phone AND email. (all of them should be same, only one or two can also be added)


You can also do the same thing for just one column. If you d like to have 3 columns to be unique separately, just create 3 statements for each column, so you ll have 3 constraint checks for each column.

Cheers,
Deniz