我有一个看起来像这样的字符串:
"0.4794255386042030002732879352156"
Run Code Online (Sandbox Code Playgroud)
这大约是罪(0.5).我想格式化字符串看起来更好
"4.794255386042e-1"
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?记住我正在处理字符串而不是数字(浮点数,双精度数).另外,我需要进行舍入以保持数字尽可能准确,我不能只是截断.如果我需要转换为不同的数据类型,我宁愿选择long double,因为常规double没有足够的精度.四舍五入之前,我想要至少12位小数.也许我可以做一个简单的sprintf()转换.
我是Python的菜鸟,并没有任何运气搞清楚这一点.我希望能够将税变量保留在代码中,以便在更改时可以轻松更新.我已经尝试了不同的方法,但只能跳过打印税行并打印相同的总数和小计值.如何将税变量乘以sum(items_count)?这是代码:
items_count = []
tax = float(.06)
y = 0
count = raw_input('How many items do you have? ')
while count > 0:
price = float(raw_input('Please enter the price of your item: '))
items_count.append(price)
count = int(count) - 1
print 'The subtotal of your items is: ' '$%.2f' % sum(items_count)
print 'The amount of sales tax is: ' '$%.2f' % sum(items_count) * tax
total = (sum(items_count) * tax) + sum(items_count)
print 'The total of your items is: ' '$%.2f' % …Run Code Online (Sandbox Code Playgroud) 我现在正在建立一个电子书管理员,读者,组织者和出版商的程序,这也是一个电子书转移(对于像Kindle这样的电子书阅读器),但我正在开发它,一个问题加速了我的想法:"日志或不?"
然后我开始考虑记录.由于许多程序都记录了操作,我开始寻找它们并查看它们如何记录事物,然后我想知道:
我正在尝试将遗留C++程序转换为objective-C.该程序需要256个可能的ASCII字符数组(每个字符8位).我正在尝试使用这种NSString方法initWithBytes:length:encoding:.不幸的是,当编码如下所示时,它会崩溃(尽管它会编译).
NSString* charasstring[256];
unsigned char char00;
int temp00;
for (temp00 = 0; temp00 <= 255; ++temp00)
{
char00 = (unsigned char)temp00;
[charasstring[temp00] initWithBytes:&char00 length:1 encoding:NSASCIIStringEncoding];
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
更新:这是Silverlight 4测试版中确认的错误.http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523052
我通过切换到完整的WPF应用程序并使用常规的旧Microsoft.Office.Interop.Word解决了这个问题.但我仍然对使用ComAutomationFactory的动态值如何使其工作非常感兴趣.
这可能更像是一个C#4.0问题,但我想要做的是利用受信任的SL4应用程序中的ComAutomationFactory类来加载Word文档,更改一些文本并打印它.
使用常规的Windows应用程序,非常简单:
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Application oWord = new Application();
Document oWordDoc = new Document();
oWord.Visible = false;
object oTemplatePath = "C:\\Users\\jwest\\Desktop\\DocumentTemplate.dotx";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Field myMergeField in oWordDoc.Fields)
Run Code Online (Sandbox Code Playgroud)
但是,在SL4中,您必须使用dynamic关键字.它工作正常,直到我尝试迭代我的字段:
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
dynamic oWord = ComAutomationFactory.CreateObject("Word.Application");
oWord.Visible = false;
object oTemplatePath = "C:\\Users\\jwest\\Desktop\\DocumentTemplate.dotx";
dynamic oWordDoc = oWord.Documents.Add(ref oTemplatePath, …Run Code Online (Sandbox Code Playgroud) 有人知道如何在JQGrid中包装列名.请在下面找到我的JSON代码
colModel:[{name:'RequestID',index:'CreditRequest.CreditRequestID',width:100,align:'left'},.....
参考上面的代码,如果内容的大小超过我希望它被包装.任何想法或评论
我很想知道它出现在屏幕上的字符串有多长.我们没有使用固定宽度的字体,所以:
"Our mother's tummy makes dummy noises."
Run Code Online (Sandbox Code Playgroud)
远远超过:
"Lilly Leadbetter lives life leisurely."
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉人物有多长时间?我不需要像素完美的精确度,只需要在大致正确的位置椭圆就足够长.CSS溢出无济于事,因为在CSS确定了多长时间之后我无法附加椭圆.
是否有API,可以锁定屏幕作为您可以从Keychain首选项添加的菜单栏条目?
此Keychain功能正在锁定屏幕但不会使系统进入睡眠状态.
我创建了一个sqlconnection,CN1.然后打开CN1.稍后在代码中有一个transactioncope.如果我在这个CN1连接上执行sql命令,这是在事务中吗?
代码看起来像这样;
SqlConnection cn1 = new SqlConnection();
cn1.Open(); //connection opened when there is no ambient transaction.
...
using(TransactionScope scope = new TransactionScope())
{
SqlCommand cmd; //a typical sql command.
...
cmd.ExecuteNonQuery(); //Is this command within transaction?
...
}
Run Code Online (Sandbox Code Playgroud) 我在网络开发商店工作,所以很自然地我们处理用户配置文件.在处理我们的某个网站时,我注意到没有"用户"类,这让我觉得奇怪,因为我们肯定有用户.相反,该站点依赖于与DataRows(这是C#)的交互,通过静态方法返回,几乎没有实例化.我问我的老板关于为用户创建一个类,他的回答是,因为对象必须重建太多,所以通常不值得.
我对Web开发比较陌生,每次重建页面时都必须实例化对象似乎有点浪费,但另一方面我总是发现面向对象的编程很有用.所以我很想知道一些意见,你们在网页开发中使用OOP多少钱?