CHF Rounding in MSSQL – CHF Runden in MSSQL

In Switzerland, the smallest unit of currency is the 5 cent piece. So, for business purposes, we usually often need to round numbers accordingly. Here’s a simple MSSQL function to do just that:

CREATE FUNCTION dbo.ufnRoundCHF (@number money)
    RETURN Round(2.*@number, 1) / 2

This gives the following results:

SELECT dbo.ufnRoundCHF(1.02)  ==> 1.00
SELECT dbo.ufnRoundCHF(1.03)  ==> 1.05
SELECT dbo.ufnRoundCHF(1.06)  ==> 1.05
SELECT dbo.ufnRoundCHF(1.075) ==> 1.10
SELECT dbo.ufnRoundCHF(1.12)  ==> 1.10
SELECT dbo.ufnRoundCHF(1.16)  ==> 1.15
SELECT dbo.ufnRoundCHF(1.19)  ==> 1.20

Linear High/Low Point Sensor Calibration

The other day, from the #raspberrypi@freenode IRC channel was looking for a way to calibrate a sensor he had on his raspi’s I2C bus. He stated that, the sensor gave a millivolt reading from an ADC, that the millivolt reading was linear to the measured parameter, and that his existing code was incomplete (no calibration) and thus produced a reading with considerable offset at the lower end of the scale, compared to a reference sensor. So he was wondering how to do High/Low Point calibration in software.

He had another requirement: He wanted to map the calibrated millivolt reading from the sensor to a zero based ppm scale in a linear fashion.

It took me a while to figure something out, but here it is:

Linear High Low Point Calibration Formular

The idea is to provide ratio-based mapping between the two scales -millivolts from sensor to value on the target scale- while referencing the zero point on the target scale to the Low Point Calibration millivolt value. The targetCalHigh variable is the target scale value at calibration high point (the high point calibration solution’s known ppm value). Because the targetCalLow value is zero as he calibrates the low point with 0ppm solution, we don’t need it for the calculation. The targetValue is the calibrated reading, mapped to whatever zero based scale targetCalHigh refers to.

did some verification of the formula with different calibration solutions (0ppm, 550ppm, 1000ppm and 2200ppm) and said that his raspi based probe provides accurate readings now when compared to the same reference meter, and that the problem appears to be solved.

Feel free to use my Math as you see fit.

New: Raspberry Pi 2

According to a news article at ElReg, a new Raspberry Pi Version 2 is being released today. Related discussion about this is ongoing at Reddit. If rumors are true, we will have a Raspberry Pi featuring 4 Cortex A7 cores @ 900MHz and (finally) a full Gig of RAM.

New Raspberry Pi 2


Here’s /proc/cpuinfo for those who are interested. The GPU is reportedly the same VideoCore IV as in previous models, as is the USB controller. The BCM2836 SoC is said to run much cooler than the BCM2835 from the 1st generation Pis. Overclocking to 1100MHz should not be a problem and will apparently be the default OC option.

rpiv2_1 rpiv2_2