|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
稍微简化了下代码
- @echo off &SetLocal EnableDelayedExpansion
- set /p x=请输入被除数:
- set /p y=请输入除数:
- set /p n=请输入欲保留的小数的位数:
- set /a count=0
- set /a bjsh=10
- :loop
- if %count% geq %n% goto start
- set /a bjsh*=10
- set /a count+=1
- goto loop
- :start
- set /a rest=%x%*%bjsh%/%y%-%x%*%bjsh%/10/%y%*10
- if "%n%"=="0" (set /a last=%x%/%y%) else (
- set /a last=%x%*%bjsh%/10/%y%-%x%*%bjsh%/100/%y%*10
- )
- if %rest% geq 5 set /a last+=1
- if "%n%"=="0" echo 结果为:%last% & pause & goto exit
- if "%n%"=="1" set /a t=%x%/%y% && echo 结果为:!t!.%last% & pause & goto exit
- set /a result=%x%*%bjsh%/100/%y%
- set /a end=%n%-1
- call echo 结果为:%%result:~0,-%end%%%.%%result:~-%end%%%%%last%% && pause
- :exit
BJSH发表于: 2007-04-01 14:43
flyinspace兄的话我得好好想想
Last edited by bjsh on 2007-4-1 at 02:53 PM ]
Slightly simplified the code
- @echo off &SetLocal EnableDelayedExpansion
- set /p x=Please enter the dividend:
- set /p y=Please enter the divisor:
- set /p n=Please enter the number of decimal places to retain:
- set /a count=0
- set /a bjsh=10
- :loop
- if %count% geq %n% goto start
- set /a bjsh*=10
- set /a count+=1
- goto loop
- :start
- set /a rest=%x%*%bjsh%/%y%-%x%*%bjsh%/10/%y%*10
- if "%n%"=="0" (set /a last=%x%/%y%) else (
- set /a last=%x%*%bjsh%/10/%y%-%x%*%bjsh%/100/%y%*10
- )
- if %rest% geq 5 set /a last+=1
- if "%n%"=="0" echo The result is: %last% & pause & goto exit
- if "%n%"=="1" set /a t=%x%/%y% && echo The result is: !t!.%last% & pause & goto exit
- set /a result=%x%*%bjsh%/100/%y%
- set /a end=%n%-1
- call echo The result is: %%result:~0,-%end%%%.%%result:~-%end%%%%%last%% && pause
- :exit
BJSH posted on: 2007-04-01 14:43
Brother flyinspace's words I need to think carefully
Last edited by bjsh on 2007-4-1 at 02:53 PM ]
|
|
2007-4-2 03:35 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
我们换个算法。。
1,获取 被除数 / 除数 的结果。
2,获取 被除数 / 除数 的余数。
3,被除数 减去 余数 则为实际整除数。
3,若余数为0,则该数被整除。提示整除,后面输出几个0
4,若不为0,则 实际整除数 / 除数为 实际整数位的值(该值一定准确)
5,获取除数的位数。假设为2位。输出的小数点为7位。(两个值不能大于10)
6,使用循环 余数 * 10(10的9次方)
7,6的结果 / 除数 (然后利用4舍5入的算法)(给出提示)输出小数位
8,输出结果 : %整数位%.%小数位%
如此。精度也满足了。你的要求也达到了。
bjsh 觉得如何?
Let's change the algorithm..
1. Get the result of dividend / divisor.
2. Get the remainder of dividend / divisor.
3. The dividend minus the remainder is the actual integer divisor.
3. If the remainder is 0, then the number is divisible. Prompt for divisibility, and then output several 0s.
4. If not 0, then actual integer divisor / divisor is the value of the actual integer part (this value must be accurate).
5. Get the number of digits of the divisor. Suppose it is 2 digits. The output decimal point is 7 digits. (Neither value can be greater than 10)
6. Use a loop to multiply the remainder by 10 (10 to the 9th power).
7. The result of 6 divided by the divisor (then use the rounding algorithm) (give a prompt) to output the decimal part.
8. Output the result: %integer part%.%decimal part%
In this way, the precision is also satisfied. Your requirement is also met.
How do you think, bjsh?
此帖被 +2 点积分 点击查看详情 评分人:【 bjsh 】 | 分数: +2 | 时间:2007-4-2 05:47 |
|
|

知,不觉多。不知,乃求知 |
|
2007-4-2 03:49 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
flyinspace兄确实给了我提醒;
系统只能精确算出第九位;
也就是说最大精确值是八位;
所以我之前的算法在精确上对于数字较小的绝对没有问题;
比如18/7
但是在大数字上比如100000/7 精度要比前者小;也是和系统最大只能算到第九位有关;
所以在这方面采用flyinspace兄的建议;
先求出余数;把大数字化成小数字;在利用余数去继续除
Brother flyinspace indeed gave me a reminder;
The system can only accurately calculate the ninth digit exactly;
That is to say, the maximum accurate value is eight digits;
So my previous algorithm is absolutely no problem for smaller numbers in terms of accuracy;
For example, 18/7
But for large numbers like 100000/7, the accuracy is smaller than the former; it is also related to the system's maximum ability to calculate up to the ninth digit;
So in this regard, I adopted Brother flyinspace's suggestion;
First find the remainder; convert the large number into a small number; then use the remainder to continue dividing
|
|
2007-4-2 04:06 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
呵呵,觉得好的话给我加分吧:)
我是不是好赖皮
Hehe, if you think it's good, give me more points : )
Am I quite cheeky
|

知,不觉多。不知,乃求知 |
|
2007-4-2 04:10 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
我要修正我前面的话
系统
数字精确度限为 32 位
所以第九位也不是确保算出来的;
例如 set /a p=4000000000/7
C:\>set /a p=4000000000/7
-42138185
所以第八为才是精确算出来的;
所以最后的精确度应为7位
I need to correct my previous statement.
System
The digital precision limit is 32 bits.
So the ninth digit is not guaranteed to be calculated;
For example, set /a p=4000000000/7
C:\>set /a p=4000000000/7
-42138185
So the eighth digit is the one calculated precisely;
Therefore, the final precision should be 7 digits
|
|
2007-4-2 04:38 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
不过是一个long int的问题。。
精度就在这里啊。
set /a p=400000000 % 7
set /a a=400000000 - % p%
set /a 整数部分=(400000000 - %a%) / 7
上面是一定整除的了。
怎么会9位不精确呢。。。。
It's just a problem with a long int. The precision is right here.
set /a p=400000000 % 7
set /a a=400000000 - % p%
set /a integer_part=(400000000 - %a%) / 7
The above must be divisible. Why is it not accurate for 9 digits...
|

知,不觉多。不知,乃求知 |
|
2007-4-2 04:49 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
 『第 22 楼』:
使用 LLM 解释/回答一下
新的代码 精度为7
- @echo off &SetLocal EnableDelayedExpansion
- set /p x=请输入被除数:
- set /p y=请输入除数:
- :n
- set /p n=请输入欲保留的小数的位数:
- if %n% gtr 7 echo 最大精确度为7位请重新输入 && goto n
- set /a count=0
- set /a bjsh=10
- set /a system_result=%x%/%y%
- set /a system_rest=%x%%%%y%
- set x=%system_rest%
- :loop
- if %count% geq %n% goto start
- set /a bjsh*=10
- set /a count+=1
- goto loop
- :start
- set /a rest=%x%*%bjsh%/%y%-%x%*%bjsh%/10/%y%*10
- if "%n%"=="0" (set /a last=%rest%) else (
- set /a last=%x%*%bjsh%/10/%y%-%x%*%bjsh%/100/%y%*10
- )
- if "%n%"=="0" if %rest% geq 5 set /a last=%system_result%+1 && echo 结果为:!last! & pause & goto exit
- if %rest% geq 5 set /a last+=1
- if "%n%"=="1" echo 结果为:%system_result%.%last% & pause & goto exit
- set /a result=%x%*%bjsh%/100/%y%
- set /a end=%n%-1
- call echo 结果为:%%system_result%%.%%result:~-%end%%%%%last%% && pause
- :exit
BJSH发表于: 2007-04-01 15:44
New code with precision 7
- @echo off &SetLocal EnableDelayedExpansion
- set /p x=Please enter the dividend:
- set /p y=Please enter the divisor:
- :n
- set /p n=Please enter the number of decimal places to retain:
- if %n% gtr 7 echo The maximum precision is 7 digits, please re-enter && goto n
- set /a count=0
- set /a bjsh=10
- set /a system_result=%x%/%y%
- set /a system_rest=%x%%%%y%
- set x=%system_rest%
- :loop
- if %count% geq %n% goto start
- set /a bjsh*=10
- set /a count+=1
- goto loop
- :start
- set /a rest=%x%*%bjsh%/%y%-%x%*%bjsh%/10/%y%*10
- if "%n%"=="0" (set /a last=%rest%) else (
- set /a last=%x%*%bjsh%/10/%y%-%x%*%bjsh%/100/%y%*10
- )
- if "%n%"=="0" if %rest% geq 5 set /a last=%system_result%+1 && echo Result is: !last! & pause & goto exit
- if %rest% geq 5 set /a last+=1
- if "%n%"=="1" echo Result is: %system_result%.%last% & pause & goto exit
- set /a result=%x%*%bjsh%/100/%y%
- set /a end=%n%-1
- call echo Result is: %%system_result%%.%%result:~-%end%%%%%last%% && pause
- :exit
Posted by BJSH on: 2007-04-01 15:44
|
|
2007-4-2 04:53 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
flyinspace兄
说的有理啊
通过循环取余;
有可能任意精度啊
Brother flyinspace,What you said makes sense!Through cyclic remainder;It may be of arbitrary precision
|
|
2007-4-2 04:55 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
最终代码了;
精确到任何一位
- @echo off
- set /p x=请输入被除数:
- set /p y=请输入除数:
- set /p n=请输入欲保留的小数的位数:
- set /a end=%n%-1
- set /a count=0
- set /a system_result=%x%/%y%
- set /a rest=%x%%%%y%
- set result=%system_result%.
- :loop
- set /a rest*=10
- set /a last=%rest%/%y%
- set /a count+=1
- if %count% geq %n% set /a rest=%rest%%%%y%*10/%y% && goto jump_loop
- set result=%result%%last%
- set /a rest=%rest%%%%y%
- goto loop
- :jump_loop
- if %n%==0 if %last% geq 5 set /a result+=1 && echo 结果为:!result!&& goto exit
- if %rest% geq 5 set /a last+=1
- echo %result%%last% & pause
BJSH发表于: 2007-04-01 18:28
Last edited by bjsh on 2007-4-1 at 06:40 PM ]
Final code;
Precise to any digit
- @echo off
- set /p x=Please enter the dividend:
- set /p y=Please enter the divisor:
- set /p n=Please enter the number of decimal places to retain:
- set /a end=%n%-1
- set /a count=0
- set /a system_result=%x%/%y%
- set /a rest=%x%%%%y%
- set result=%system_result%.
- :loop
- set /a rest*=10
- set /a last=%rest%/%y%
- set /a count+=1
- if %count% geq %n% set /a rest=%rest%%%%y%*10/%y% && goto jump_loop
- set result=%result%%last%
- set /a rest=%rest%%%%y%
- goto loop
- :jump_loop
- if %n%==0 if %last% geq 5 set /a result+=1 && echo The result is: !result!&& goto exit
- if %rest% geq 5 set /a last+=1
- echo %result%%last% & pause
BJSH posted on: 2007-04-01 18:28
Last edited by bjsh on 2007-4-1 at 06:40 PM ]
|
|
2007-4-2 05:46 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
这个代码的思想要归功于flyinspace
本想给他加十分;可惜论坛限制只能加两分..
愿看过的各位 替我实现愿望
The idea of this code is attributed to flyinspace. I originally wanted to give him ten points; unfortunately, the forum restricts it to only two points..
May all those who have read it fulfill my wish for me
|
|
2007-4-2 05:49 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
以前的那些突破了下限;
无法计算高于10^9次的下面这个经过修改后;突破了上下限;
可以计算任意位数字;并且可以精确到任意位数;(似乎太大比如1百万位会提示输出行太长)
- @echo off & setlocal enabledelayedexpansion
- set /p x=请输入被除数:
- set /p y=请输入除数:
- if %y% gtr 2000000000 echo 除数太大 && goto exit
- set /p n=请输入欲保留的小数的位数:
- if %x% gtr 2000000000 goto big
- :start
- set /a count=0
- set /a system_result=%x%/%y%
- set /a rest=%x%%%%y%
- set result=%system_result%.
- :loop
- set /a rest*=10
- set /a last=%rest%/%y%
- set /a count+=1
- if %count% geq %n% set /a rest=%rest%%%%y%*10/%y% && goto jump_loop
- set result=%result%%last%
- set /a rest=%rest%%%%y%
- goto loop
- :jump_loop
- if %n%==0 if %last% geq 5 set /a result+=1 && echo 结果为:!result!&& goto exit
- if %rest% geq 5 set /a last+=1
- echo 结果为:%result%%last% && goto exit
- :big
- set /a l=0
- set result=
- :big_loop
- set p=%x:~0,1%
- set /a m=%l%*10+%p%
- set /a s=%m%/%y%
- set result=%result%%s%
- if "%result%"=="0" set result=
- set /a l=%m%%%%y%
- set x=%x:~1%
- if not defined x goto big_end
- goto big_loop
- :big_end
- set result=%result%.
- set /a count=0
- set rest=%l%
- goto loop
- :exit
- pause
BJSH发表于: 2007-04-01 18:56
Last edited by bjsh on 2007-11-22 at 10:30 PM ]
The previous ones broke the lower limit;
The following one after modification, which cannot calculate higher than 10^9 times, broke both the upper and lower limits;
Can calculate any number of digits; and can be precise to any number of digits; (it seems that for something too large like 1 million digits, it will prompt that the output line is too long)
- @echo off & setlocal enabledelayedexpansion
- set /p x=Please enter the dividend:
- set /p y=Please enter the divisor:
- if %y% gtr 2000000000 echo The divisor is too large && goto exit
- set /p n=Please enter the number of decimal places to keep:
- if %x% gtr 2000000000 goto big
- :start
- set /a count=0
- set /a system_result=%x%/%y%
- set /a rest=%x%%%%y%
- set result=%system_result%.
- :loop
- set /a rest*=10
- set /a last=%rest%/%y%
- set /a count+=1
- if %count% geq %n% set /a rest=%rest%%%%y%*10/%y% && goto jump_loop
- set result=%result%%last%
- set /a rest=%rest%%%%y%
- goto loop
- :jump_loop
- if %n%==0 if %last% geq 5 set /a result+=1 && echo The result is: !result!&& goto exit
- if %rest% geq 5 set /a last+=1
- echo The result is: %result%%last% && goto exit
- :big
- set /a l=0
- set result=
- :big_loop
- set p=%x:~0,1%
- set /a m=%l%*10+%p%
- set /a s=%m%/%y%
- set result=%result%%s%
- if "%result%"=="0" set result=
- set /a l=%m%%%%y%
- set x=%x:~1%
- if not defined x goto big_end
- goto big_loop
- :big_end
- set result=%result%.
- set /a count=0
- set rest=%l%
- goto loop
- :exit
- pause
BJSH posted on: 2007-04-01 18:56
Last edited by bjsh on 2007-11-22 at 10:30 PM ]
|
|
2007-4-2 07:45 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
无法解决除数大于10^9的问题
Last edited by bjsh on 2007-4-1 at 08:53 PM ]
Unable to solve the problem where the divisor is greater than 10^9
Last edited by bjsh on 2007-4-1 at 08:53 PM ]
|
|
2007-4-2 08:01 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
Originally posted by bjsh at 2007-4-1 07:01 PM:
无法解决被除数大于10^9的问题
被除数 / 除数 = 结果中。
被除数是可以大于10的9次方的。。
但除数不可以。。
set 被除数=9999999999999999999999999999999
假设这个9有20位。。当然长度可以任意。。
使用 set new=%被除数:~0,9%取9位数出来。。
当然在应用级别的时候。。我们会用for循环解决连续值的问题。。
这里只说明一种情况。。其他的情况你自己搞定啊:)
首先判断 new 是否大于 除数
是--》大于则开始做取余运算。。。
假设除数是111111110。
然后按照上面的方法获得精确的值后。。
获取余数的位数。。
此例子为一位。。。值为9。。
然后在后面利用 set 补上8位。。
如此,循环。。。
把20位的数字全部取完。。
则整数部分的代码搞定了。。
小数部分你自己也会搞啦。。
Originally posted by bjsh at 2007-4-1 07:01 PM:
Unable to solve the problem where the dividend is greater than 10^9
In dividend / divisor = result.
The dividend can be greater than 10^9.
But the divisor cannot.
set dividend=9999999999999999999999999999999
Assume this 9 has 20 digits. Of course, the length can be arbitrary.
Use set new=%dividend:~0,9% to take out 9 digits.
Of course, at the application level, we will use a for loop to solve the problem of continuous values.
Here, only one situation is explained. You can handle other situations by yourself :)
First, judge whether new is greater than the divisor
Yes --》If it is greater, start doing the remainder operation...
Assume the divisor is 111111110.
Then, after obtaining the precise value according to the above method...
Obtain the number of digits of the remainder.
In this example, it is one digit... and the value is 9.
Then, use set to fill in 8 digits later.
In this way, loop...
Take out all 20 digits of the number.
Then the code for the integer part is done..
You can also handle the decimal part by yourself..
|

知,不觉多。不知,乃求知 |
|
2007-4-2 09:26 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
我上面写错了;
是没法解决 除数大于 10^9 的问题;
至于被除数我最后一个代码用的思想和 flyinspace是一样的;
那段代码 对于被除数任意位都可以的
Last edited by bjsh on 2007-4-1 at 08:51 PM ]
I made a mistake above;
It's impossible to solve the problem where the divisor is greater than 10^9;
As for the dividend, the idea used in my last code is the same as flyinspace's;
That code is applicable to any number of digits of the dividend
Last edited by bjsh on 2007-4-1 at 08:51 PM ]
|
|
2007-4-2 09:49 |
|
|
nanhui112
初级用户
 
积分 127
发帖 59
注册 2007-11-13
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
;)特大数 我采取循环截取取数 但还是有问题 如123456789123456
先取前九位计算 后面再补0 把结果相加计算 有涉及到特大数相加的问题
并且结果也不是很正确 涉及到小数问题 一放大 就有很大数字差距了
看来 cmd 不适合计算 只能做到这个份拉~~~
----前面的都是高手 学习拉 加倍努力拉:)
Last edited by nanhui112 on 2008-1-28 at 04:43 PM ]
;)Large number. I use cyclic interception to get numbers, but there are still problems. For example, 123456789123456. First take the first nine digits for calculation, then add zeros at the end, and then add the results. There is a problem with adding very large numbers, and the result is not very correct. There is a decimal problem. When magnified, there is a big difference in numbers. It seems that cmd is not suitable for calculation. I can only do this much~~~
----The previous ones are all experts. I will study hard and work harder: )
Last edited by nanhui112 on 2008-1-28 at 04:43 PM ]
|
|
2008-1-28 16:28 |
|