2016-03-24 33 views
0

在下面的XQuery一切正常,只是在該線下方,上面寫着:金額超過一個百萬顯示奇怪的是使用XQuery

<h2>Total word count: {format-number($sum, "0")}</h2> 

如果總和超過一百萬的它顯示爲:

「1.516908E6」

我不明白這個數字。例如,爲什麼會有「E」?

任何低於百萬次打印預期,例如:

「72188」 爲72188。

我可能缺少一些基本的東西,但我會很感激任何幫助。

開始的XQuery

xquery version "3.0"; 

declare namespace tei="http://www.tei-c.org/ns/1.0"; 

declare option exist:serialize "method=html media-type=text/html ident=no"; 

let $commentaryid := request:get-parameter('commentaryid', '') 
let $collection := concat("scta", "/", $commentaryid) 
let $terms := 
    <terms> 
     { 
      util:index-keys(
       collection(concat("/db/apps/", $collection))//tei:p, 
       "", 
       function($key, $count) { 
        <term name="{$key}" count="{$count[1]}" 
         docs="{$count[2]}"/> 
       }, -1, "lucene-index") 
     } 
    </terms> 

let $sum := sum($terms//@count) 
return 
    <html> 
     <head> 

     </head> 
     <body> 
      <h1>Frequency analysis for {$collection}</h1> 
       <h2>Total word count: {format-number($sum, "0")}</h2> 
      <table> 
       <tr> 
        <td>Term</td> 
        <td>Frequency</td> 
        <td>Percentage</td> 
       </tr> 
       { 
        for $term in $terms//term 

         let $frequency := xs: integer($term/@count/string()) 
         let $percentage := format-number(($term/@count div $sum), "%.00") 
         order by $frequency descending 
         return 

          <tr> 
           <td>{$term/@name/string()}</td> 
           <td>{$frequency}</td> 
           <td>{$percentage}%</td> 
          </tr> 
       } 
       </table> 
       </body> 
       </html> 
+0

爲了確認,我假設你使用'util:index-keys()'表示你的XQuery實現是eXist。你使用的是什麼版本的eXist? – joewiz

+0

嗨@joewiz,我正在運行3.0.RC1 – Jeff

+1

https://en.m.wikipedia.org/wiki/Scientific_notation#E_notation – har07

回答

0

中的XPath規則轉換XS:雙串說,不到百萬分之一或一百多萬應該在「科學記數法」進行格式化數字。如果這不是您想要的,那麼最好將數字轉換爲整數或小數 - 最好儘可能早。在你的情況下,轉化爲xs:double正在發生的事情隱含你寫

sum($terms//@count) 

,你可以通過避免它

sum($terms//xs:integer(@count)) 

後記

我不認爲我讀了你的問題小心翼翼。我沒有看到你實際上調用了format-number()來輸出值。除非明確要求,否則format-number不應以指數/科學記數法產生輸出。所以這裏還有其他的東西,這可能是eXist特有的。