First thing check for empty string when and condition in CASE WHEN, Secondly check the value of CountMaterialsConfirment and CountMaterials, If its increasing then change decimal to (8,3) isn't going to do anything if it's greater than 99999.999 - you need to increase the number of digits before the decimal. Also try decimal(9,2) or decimal(10,2) or whatever according to your data value. Try the modified code:
FORMAT(CASE WHEN ((ISNULL(c.CountMaterialsConfirment, '') = '') AND (ISNULL(c.CountMaterials, '') = '')) THEN 0
ELSE (cast(c.CountMaterialsConfirment as decimal(9,2)) / cast(m.CountMaterials as decimal(9,2))) * 100 END,'N2') as totalpercentage