batch file calculator with decimals

Hewlett-packard / Rc659aa-aba a1632x
July 10, 2009 at 13:30:26
Specs: Microsoft Windows Vista Home Premium, 2 GHz / 2045 MB
 hi,i made a calculator in a batch file using this code:@echo offtitle My Calculatorcls:aecho.set /p math=Whatchoo gonna calculate? set /a math2=%math%echo %math% = %math2%goto ahowever, i soon discovered it didnt show decimals. is there any way to do this??

See More: batch file calculator with decimals

#1
July 10, 2009 at 14:00:38
 Yes, by coding a lot of statement and using substring manipulation operators for formatting results.NT batch math is aimed to perform simple operations on integers only. As I said you can spend a lot of coding to perform even floating point computing, but that is no worth.In the Jurassic eve I coded such programs for ancient minicomputers and I can assure it is a hard work.

Report •

#2
July 10, 2009 at 14:06:41
 any idea where to start?

Report •

#3
July 10, 2009 at 14:20:34
 Start by learning NT batch math operators and string manipulation as explained by the quick (unfriendly) on-line help you get typing Set /? at prompt. Beware you are going onto the road to the hell.

Report •

Related Solutions

#4
August 4, 2009 at 16:10:14

Report •

#5
August 4, 2009 at 16:55:27
 >> any idea where to start?the next best thing you can use, natively, is vbscript. Else, use a real programming language, like Python, or Perl. GNU win32 packages | Gawk

Report •

#6
August 8, 2009 at 12:35:12
 @ricardo647wow. thats an epic code.thanks

Report •

#7
August 8, 2009 at 14:02:30
 Here's a perl solution.```#!/usr/bin/perl use strict; use warnings; print "Whatchoo gonna calculate? "; chomp(my \$calc = ); my \$answer = eval \$calc; print \$answer, \$/; ```

Report •

#8
August 8, 2009 at 19:43:41
 @Fish>>Here's a perl solution.though its workable, however, still need input sanitizing(eg, check for numbers...etc)```# ./perl.pl Whatchoo gonna calculate? system("ls") ```that said, here's an equivalent Python solution```choice = raw_input("what you want to calculate") print eval(choice,{},{}) ``` GNU win32 packages | Gawk

Report •

#9
August 8, 2009 at 23:26:51
 Yes, both of our examples need input sanitizing.But here's the equivalent Perl solution of the Python solution.C:\test>type calc.plprint "Enter your math equation ";print eval ;C:\test>calc.plEnter your math equation (5+3) * 7 / 4.454 * 36452.626852267625

Report •

#10
August 9, 2009 at 04:28:17
 Python's eval can be passed parameters to minimise such things, though IMO, it may not be the most thorough, however it is at least something. See herePerl's eval() is much more "dangerous" (for lack of better word) GNU win32 packages | Gawk

Report •

#11
August 9, 2009 at 08:59:19
 I wouldn't use the word "dangerous", but it might need more error handling code than Python's eval, only a person that knows each language equally well can say for sure.However, I wouldn't use something this simplistic in production code, and I doubt that you would either. I'd start by searching cpan for related modules that have already worked out the some of the problems.

Report •