static CCUnit decToFrac(float dec) { int integral = (int)decimal.Truncate((decimal)dec); int fraction = (int)(((decimal)dec - decimal.Truncate((decimal)dec)) * 1000); float newError = (float)decimal.Truncate((decimal)(fraction / 62.5)); CCUnit result = new CCUnit(integral, (int)(fraction / 62.5), 16, newError); result.reduce(); return(result); }
// POST: api/CarpCalc public void Post([FromBody] string value) { HttpContext c = HttpContext.Current; c.Response.ContentType = "application/json"; c.Response.ContentEncoding = Encoding.UTF8; System.IO.Stream body = c.Request.InputStream; System.Text.Encoding encoding = c.Request.ContentEncoding; System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); if (c.Request.ContentType != "application/json") { c.Response.Write("incorrect content type"); c.Response.End(); } else { string s = reader.ReadToEnd(); try { Request r1 = JsonConvert.DeserializeObject <Request>(s); CCUnit result = null; if (r1.calcOperator == '+') { if (r1.CCUnits.Length == 2) { result = r1.CCUnits[0] + r1.CCUnits[1]; } } if (result != null) { s = JsonConvert.SerializeObject(result, Formatting.Indented, new JsonConverter[] { new StringEnumConverter() }); } else { s = "ERROR: Invalid Input Format."; } c.Response.Write(s); c.Response.End(); } catch (Exception e) { } } }
static CCUnit calculate(CCUnit opd1, CCUnit opd2, char optr) { return(opd1); }