Generic truncate function